413 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?  

1 Answer

Related questions

2 votes
2 votes
1 answer
1
iarnav asked May 5, 2017
323 views
void main() { int *ptr; ..... ..... { int ch; ptr = &ch; } ..... // Here ptr is dangling pointer }Since here's no function calling and only main(). So, I am not able to u...
0 votes
0 votes
1 answer
2
Sahil Raza asked Oct 13, 2018
237 views
What is the differences between static and extern in C ? How it work ?
1 votes
1 votes
0 answers
3
Vishwanath Ravula asked Nov 23, 2016
145 views
What is difference between static scoping and dynamic scoping?
1 votes
1 votes
1 answer
4