Ok, I know this may be no big deal to you vets out there but something strange happend when I left a variable uninitialized at first. Here's the code:
When I ran this program, x return a value of 65 the first time and then 66 (obviously) the second time. 65 is a number I assigned to x in a previous program! Values in variables actually stay in variables between programs?! Does this have anything to do with memory leaks? If so, it makes sense.Code:#include <iostream> using namespace std; int main() { int x; cout << "x = " << x << endl; x = x + 1; cout << "x = " << x << endl; system("pause"); return 0; }
I'm used to visual basic in that the variables are always set to zero or null when first declared. Thanks to anyone who can answer my question.




Reply With Quote