none
Why in C or C++ are initialized with zero while local variables are not RRS feed

  • Question

  • #include <stdio.h>
    int a;
    int main(){
    	int b;
    	printf("%d\t%d",a ,b);//0	      garbage
    	return 0;
    }

    why this why global variable is initialized with zero
    Monday, October 14, 2019 10:10 AM

Answers

  • Hi question_asker.

    This question should be asked in a C/C++ forum: this forum is intended for topics related to Microsoft Learning and Certification.
    In the C programming language, a global variable is always initialized to 0, while this does not happen for any local variable (like the "b" one): they must explicitly initialized.

    Bye.


    Luigi Bruno
    MCP, MOS, MTA, MCTS, MCSA, MCSE

    Monday, October 14, 2019 1:18 PM