in Programming in C
415 views
0 votes
0 votes
#include <stdio.h>
 
/* global variable declaration */
int g = 20;
 
int main () {

  /* local variable declaration */
  int g ;
 
  printf ("value of g = %d\n",  g);
 
  return 0;
}




why this printing value of g is 0 instead of garbage  because g is declared which is local variable  in main function.    are variables inside main function by default global?  

in Programming in C
415 views

2 Comments

It should be garbage.
0
0
0
0

1 Answer

0 votes
0 votes
no, by default variables inside main function is not by default global