One of the reasons I allmost never get any real work done, I think, is that I allmost allways stumble over small things that I don't understand. And then, instead of pragmatically solving it another way, I stop everything.
This time it's about declaring and initializing integer variables in C++:
Silly me though that !<variable> would return true if the variable was initialized, and false if it wasn't. And for the first two integers in this example - l and h - it seems to work like that. But not for the third, s. The printout of the above is:Code:int l, h, s; if (!l) cout << "Not l!" <<endl; if (!h) cout << "Not h!" <<endl; if (!s) cout << "Not s!" <<endl;
That's it. Apparently, it has decided that s is indeed intialized, even though it doesn't happen anywhere. If I change the variable declaration to this:
Then the printout is:Code:int l, s, h;
So it's obviously the third one that's different. I might be completely off here, of course, since I've barely started looking at C++. Is this a non-valid way to check if a variable is initialized? Even if it is, I'm curious as to why the result is different for the third variable. There's probably a basic and obvious explanation, I know :-)