Greetings EveryOne
What does the value of a not valued variable represents?
Isn't it a null variable, shouldn't a null variable be equal to 0?
Thanks In AdvanceCode:#include <stdio.h> int main() { int x; printf("x = %d\n", x); return 0; }
Greetings EveryOne
What does the value of a not valued variable represents?
Isn't it a null variable, shouldn't a null variable be equal to 0?
Thanks In AdvanceCode:#include <stdio.h> int main() { int x; printf("x = %d\n", x); return 0; }
If you have an uninitialised variable, then all bets are off as to what you get.
- it might be zero (consistently)
- it might be non-zero (consistently)
- it might be random (over a small set of values)
- it might be truly random (or seem so)
- it might just crash your program.
Doing absolutely anything (adding more code, changing your compiler, changing your compiler flags) can make anything else happen.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
According to C FAQ :
what do you advice me to do, especially when declaring arrays as they might be long or moderately long?Variables with automatic duration (i.e. local variables without the static storage class) start out containing garbage, unless they are explicitly initialized. (Nothing useful can be predicted about the garbage.)