Consider the following code snippet
int main(){
int a, b, c;
printf("%d %d %d", a, b, c);
return 0;
}
This is going to display some garbage value.
Now, consider this snippet.
int main(){
int a, b, c = 0;
printf("%d %d %d", a, b, c);
return 0;
}
This displays 0 0 0 for every execution. But I've only initialized variable c to 0. Is this some shorthand for doing something like, int a=0, b=0, c=0;
Don't know how to look for such doubt in official documentation.
aandbare indeterminate in both versions. It's just by accident that they're being set to0in the second one. The compiler might be using an optimization when initializingcthat happens to fill the whole block of memory with zeroes.a,bare being initialized to0, that is still garbage value?-Soption. Or better yet, step through the assembly with a debugger.