C Quiz – 111 | Question 5

Pick the best statement for the below program:

filter_none

edit
close

play_arrow

link
brightness_4
code

#include "stdio.h"
  
int size = 4;
int arr[size];
  
int main()
{
 if(arr[0])
  printf("Initialized to ZERO");
 else
  printf("Not initialized to ZERO");
  
 return 0;
}

chevron_right


(A) No compile error and it’ll print “Initialized to ZERO”.
(B) No compile error and it’ll print “Not initialized to ZERO”.
(C) Compile error because size of arr has been defined using variable outside any function.
(D) No compile error and it’ll print either “Initialized to ZERO” or “Not initialized to ZERO” depending on what value is present at arr[0] at a particular run of the program.


Answer: (C)

Explanation: An array whose size is specified as variable can’t be defined out any function. It can be defined only inside a function. So putting arr[size] outside main() would result in compile error. Answer is C.

Quiz of this Question



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.