Let's assume that I'm programming this code in C
.
If I have an uninitialized variable number
I can't know what will be its value. BUT...
WHAT IS that random value? What do I have in a memory dump? Is it because an address is tried to be read and nothing comes out?
I tried to debug my program but I'm still a newbie so I get lost easily.
Also, if I add a zerowillcome
variable (see Code 2) my number
value won't be random anymore: it will be 0
. I can't understand why this is happening but I think it regards the order variables are pushed onto the stack. Am I right? Can someone picture me what exactly is happening, step by step?
PS: Those other variables are there since this is a snippet of other code, so I do not know if removing them I'd be able to alter the application behaviour: my attention was caught by that strange behaviour caused by adding the zerowillcome
variable.
Code 1:
int main (int argc, char *argv[])
{
int number, var1, var2, tmp, tmp2;
printf("number: %d", number); // <- insert random number here
return 0;
}
Code 2:
int main (int argc, char *argv[])
{
int number, var1, var2, tmp, tmp2, zerowillcome;
printf("number: %d", number); // <- 0 !!!
return 0;
}