lundi 23 juillet 2018

initialization of static variable in C++ vs C

why the following code runs fine in c++ but give compile error in c language?

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

Aucun commentaire:

Enregistrer un commentaire