This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
The compiler is stupid, basically. It will not realize that all possibilities ensure that y will be initialized. However, if you replace the second if with an else, the program will compile and run. Just to be on the safe side, make it a habit of initializing all local variables at the onset.
the compiler is ensuring that y is initialized. Since the value of x could change, there is no guarantee(to the compiler) that y is initialized. If you initialize y = 0, this will compile and run. Line 1 in main() int x = 10, y = 0;
Joined: Apr 23, 2002
Thanks, that sounds trip cuestion. I know, is the best way to make it a habit of initializing all local variables at the onset. But the exam have trip/traps Thank you very much