C Array MCQ


Q1) What is the output of C program with arrays and pointers.?
int main()
{
    int size=4;
    int a[size];
    a[0]=5;a[1]=6;
    a[2]=7;a[3]=8;
    printf("%d %d", *(a+2), a[1]);
}
  1. 8 6
  2. 7 6
  3. 6 6
  4. Compiler error

Answer:- (B).
Explanations :variable size is already defined. So a[size] is allowed. *(a+2) == a[2].
Q2) What is the output of C program with arrays.?
  int main()
{
    int ary(3)=[20,30,40];
    printf("%d", a(1));
}
  
  1. 20
  2. 30
  3. 0
  4. Compiler error

Answer:- (D).
Explanations :Array should be declared and defined with Square Brackets. Use ary[2] instead of ary(2).

int ary[3]={20,30,40};
Q3) What is the output of C Program with arrays.?
 int main()
{
    int rollno[3]=[1001,1002,1003];
    printf("%d", rollno[1]);
}
 
  1. 1002
  2. 1003
  3. address of 1002
  4. Compiler error

Answer:- (D).
Explanations :You should use Flower Brackets or Braces to define elements like {1,2,3}. It is wrong to use [1,2,3].
Q4) What is the output of C program with arrays.?
int main()
{
   char grade={'A','B','C'};
   printf("%c", grade[0]);
}
  1. A
  2. B
  3. 41
  4. Compiler error

Answer:- (D).
Explanations :Notice that char grade is an character variable, not Character array variable. So declare as char grade[] = {'A','B','C'};
Q5) What is the value of an array element which is not initialized.?
  1. By default Zero 0
  2. 1
  3. Depends on Storage Class
  4. None of the above.

Answer:- (C).
Explanations :For Automatic variables, default value is garbage. For static and global variables, default value is 0.
Q6) What happens when you try to access an Array variable outside its Size.?
  1. Compiler error is thrown
  2. 0 value will be returned
  3. 1 value will be returned
  4. Some garbage value will be returned.

Answer:- (D).
Explanations :None
Q7) What is the size of an array in the below C program statement.?
int main()
{
    int ary[9];
    return 0;
}
  1. 8
  2. 9
  3. 10
  4. None of the above

Answer:- (B).
Explanations :Array size is 9. So memory occupied by 9 integers are kept aside by the CPU.
Q8) What is the minimum and maximum Indexes of this below array.?
int main()
{
    int ary[9];
    return 0;
}
  1. -1, 8
  2. 0, 8
  3. 1,9
  4. None of the above

Answer:- (B).
Explanations :Array index starts with 0 and ends with 8 for a 9 Size array. ary[0] to ary[8] are meaningful.
Q9) Can we change the starting index of an array from 0 to 1 in any way.?
  1. Yes. Through pointers.
  2. Yes. Through Call by Value.
  3. Yes. Through Call by Reference.
  4. None of the above.

Answer:- (D).
Explanations :No. You can not change the C Basic rules of Zero Starting Index of an Array.
Q10) What is the need for C arrays.?
  1. You need not create so many separate variables and get confused while using.
  2. Using a single Array variable, you can access all elements of the array easily.
  3. Code maintainability is easy for programmers and maintainers.
  4. All the above.

Answer:- (D).
Explanations :None