-
Blank Variables
Why do blank variables display different "weird" results in different computers?
for example:
#include <iostream.h>
int main
{
int a;
double b;
char c;
cout<<a<<"\t"<<b<<"\t"<<c;
return(0);
}
differents values shows up on the screen for a,b and c when the program is run in different computers. Can anyone tell me why this happens? Thanks a bunch.
-
the memory addresses your variables correspond to might have been used by an earlier program, thus your just picking up what just so happens to be left in those memory addresses. one of the importances of initializing data, besides assuming an int is already 0; although static and global variables are automically initialized. I hope this is right or else i'll look like a fool.
-
i think that about sums it up... what i am curious about tho is why memory isn't cleared after freeing...
-
"what i am curious about tho is why memory isn't cleared after freeing..."
would be a waste of cpu time, just speculating..
-
Clearing memory after freeing is unnecessary. It would take precious time!
-
Thanks ^.^
Wow, you guys sure answer questions fast around here, well, I am new, so ya. Well, thanks for your help, I really appreciate it, I will know tomorrow which answer is right. Teacher's gonna tell us, I think. I will post it up here, k? Thanks again.
-
Registered!
Hallo, I just registered, like that little bunny? Hehe, well, I gtg now. Bye!
-
-
Answer
The teacher said, the value that outputs on the screen is what had been on the RAM before. What I mean is, when a variable is declared, a space is made for the variable right? BUt that space was used before by some other program. IF you don't input something to erase that memory and replace it with something yours, the computer will show up what had been in that memory space originally. So, here is the answer. It was actually a class-bonus mark thing. WE only got 2 bonus marks, (yesterday, it was 10) because the teacher had to guide us to the answer. So ya. Thanks for the help anyways. Bye! :)