How garbage values are assigned to variables in c

后端 未结 4 360
后悔当初
后悔当初 2020-11-29 11:59

C code :

int a;
printf(\"\\n\\t %d\",a); // It\'ll print some garbage value;

So how does these garbage values are assigne

4条回答
  •  青春惊慌失措
    2020-11-29 12:44

    int a;

    While declaring a variable, the memory is allocated. But this variable is not assigned which means the variable a is not initialized. If this variable a is only declared but no longer used in the program is called garbage value. For example:

    int a, b;
    
    b=10;
    printf("%d",b);
    return 0;
    

    Here it's only declared but no longer assigned or initialized. So this is called garbage value.

提交回复
热议问题