The Gateway to Computer Science Excellence
0 votes
93 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 by Loyal (5.3k points) | 93 views
0
It should be garbage.
0

1 Answer

0 votes
no, by default variables inside main function is not by default global
by (93 points)
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,741 questions
57,252 answers
198,062 comments
104,698 users