Thread: Blank Variables

  1. #1
    Michelle
    Guest

    Question 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.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    61
    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.

  3. #3
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    i think that about sums it up... what i am curious about tho is why memory isn't cleared after freeing...
    hasafraggin shizigishin oppashigger...

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    61
    "what i am curious about tho is why memory isn't cleared after freeing..."

    would be a waste of cpu time, just speculating..

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    164
    Clearing memory after freeing is unnecessary. It would take precious time!
    // Gliptic

  6. #6
    Michelle
    Guest

    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.

  7. #7
    Back! ^.^ *Michelle*'s Avatar
    Join Date
    Oct 2001
    Posts
    568

    Talking Registered!

    Hallo, I just registered, like that little bunny? Hehe, well, I gtg now. Bye!
    Michelle (o^.^o)
    *Unique*
    Kaomoji House

  8. #8
    Registered User
    Join Date
    Aug 2001
    Posts
    61
    cute.

  9. #9
    Back! ^.^ *Michelle*'s Avatar
    Join Date
    Oct 2001
    Posts
    568

    Lightbulb 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!
    Michelle (o^.^o)
    *Unique*
    Kaomoji House

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  2. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  3. esbo's data sharing example
    By esbo in forum C Programming
    Replies: 49
    Last Post: 01-08-2008, 11:07 PM
  4. Check for a blank cd-r
    By waldis in forum C++ Programming
    Replies: 3
    Last Post: 02-23-2003, 06:16 PM
  5. functions to return 2 variables?
    By tim in forum C Programming
    Replies: 5
    Last Post: 02-18-2002, 02:39 PM