Vidyalelo
C Programming · all questions

Arrays and Strings
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

133

Questions

2/7

Page

Pick an option on a question to see the right answer and solution.

What is the purpose of the fgets function in C?

Select an option to see the answer and solution.

What does the strtok function do in C?

Select an option to see the answer and solution.

How do you declare a two-dimensional integer array in C with 3 rows and 4 columns?

Select an option to see the answer and solution.

What is the result of the expression strlen("Hello") in C?

Select an option to see the answer and solution.

Which function is used to find the first occurrence of a character in a string in C?

Select an option to see the answer and solution.

How do you declare a string in C that can store up to 50 characters?

Select an option to see the answer and solution.

What is the purpose of the strncpy function in C?

Select an option to see the answer and solution.

Which function is used to convert a string to an integer in C?

Select an option to see the answer and solution.

What does the fgets function in C do when it encounters a newline character?

Select an option to see the answer and solution.

How can you check if two strings are equal in C?

Select an option to see the answer and solution.

What is right way to Initialize array?

Select an option to see the answer and solution.

What will be the output of the program?
#include<stdio.h>
void main()
{
    int a[5] = {5, 1, 15, 20, 25};
    int i, j, m;
    i = ++a[1];
    j = a[1]++;
    m = a[i++];
    printf("%d, %d, %d", i, j, m);
}

Select an option to see the answer and solution.

What will be the output of following program code?
#include <stdio.h>
int main(void)
{
    char p;
    char buf[10] = {1, 2, 3, 4, 5, 6, 9, 8};
    p = (buf + 1)[5];
    printf("%d", p);
    return 0;
}

Select an option to see the answer and solution.

An array elements are always stored in ________ memory locations.

Select an option to see the answer and solution.

Let x be an array. Which of the following operations are illegal?
I.   ++x
II. x+1
III. x++
IV. x*2

Select an option to see the answer and solution.

What is the maximum number of dimensions an array in C may have?

Select an option to see the answer and solution.

Size of the array need not be specified, when

Select an option to see the answer and solution.

Consider the following type definition.
typedef char x[10];
x myArray[5];

What will sizeof(myArray) be ? (Assume one character occupies 1 byte)

Select an option to see the answer and solution.

What will be printed after execution of the following code?
void main()
{
      int arr[10] = {1,2,3,4,5};
      printf("%d", arr[5]);
}

Select an option to see the answer and solution.

What will be the output of the following program?
void main()
{
      char str1[] = "abcd";
      char str2[] = "abcd";
      if(str1==str2)
            printf("Equal");
      else
            printf("Unequal");
}

Select an option to see the answer and solution.