search
Log In
0 votes
122 views
#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 122 views
0
It should be garbage.
0

1 Answer

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

Related questions

2 votes
1 answer
1
135 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 understand which variable is going out of scope? ptr or ch? Thanks all!
asked May 5, 2017 in Programming iarnav 135 views
0 votes
1 answer
2
59 views
What is the differences between static and extern in C ? How it work ?
asked Oct 13, 2018 in Programming Sahil Raza 59 views
1 vote
0 answers
3
47 views
What is difference between static scoping and dynamic scoping?
asked Nov 23, 2016 in Programming Vishwanath Ravula 47 views
3 votes
2 answers
4
836 views
Choose the False statements: (a) The scope of a macro definition need not be the entire program (b) The scope of a macro definition extends from the point of definition to the end of the file (c) A macro definition may go beyond a line (d) None of the above
asked Nov 4, 2017 in Programming sunil sarode 836 views
...