Skip to content
Related Articles

Related Articles

C | Storage Classes and Type Qualifiers | Question 19
  • Difficulty Level : Easy
  • Last Updated : 10 Jul, 2018




#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; 
}

(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

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.
My Personal Notes arrow_drop_up
Recommended Articles
Page :