C | Storage Classes and Type Qualifiers | Question 19

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <stdio.h>
int main() 
  int x = 10; 
  static int y = x; 
    
  if(x == y) 
     printf("Equal"); 
  else if(x > y) 
     printf("Greater"); 
  else
     printf("Less"); 
  return 0; 
}

chevron_right


(A) Compiler Error
(B) Equal
(C) Greater
(D) Less


Answer: (A)

Explanation: In C, static variables can only be initialized using constant literals. This is allowed in C++ though.  See this GFact for details.

Quiz of this Question



My Personal Notes arrow_drop_up