Huge pre-assigned values to variables

This is a discussion on Huge pre-assigned values to variables within the C++ Programming forums, part of the General Programming Boards category; Ok...When I declare a variable. For this case, lets say x, but it doesn't really matter. I call upon x ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Location
    Rochester
    Posts
    40

    Huge pre-assigned values to variables

    Ok...When I declare a variable. For this case, lets say x, but it doesn't really matter. I call upon x and it is just a massive seven or more digit number. I haven't even set x to anything yet, so I'm pretty sure that its not supposed to do that and i'm afraid i might screw up my computer.

    Can anyone tell me what's going on?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,256
    Can anyone tell me what's going on?
    You are getting garbage values since you did not initialise those variables.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2007
    Location
    Rochester
    Posts
    40
    ok, I guess that makes sense. Just out of curiousity, where do these garbage values come from.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Whatever was in that memory space before. Whether it was from computer startup, a previous program, your program, or whatever.

  5. #5
    Registered User
    Join Date
    Dec 2007
    Location
    Rochester
    Posts
    40
    Thanks to both of you for your help, I thought I might be messing up my computer or something.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Note also that the compiler MAY do things like "fill all stack-space" [which is where your variables are stored] to some constant value. Microsoft Visual Studio fills memory with a patterns such as 0xCCCCCCCC or 0xDDDDDDDDD. This makes it a bit easier to idenitfy a variable that hasn't been set to anything, rather than it containing some completely random value. [This only happens in debug mode - it also slows down the code, particularly if you have large arrays in local functions].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New compiler - Weird errors -,-.
    By Blackroot in forum C++ Programming
    Replies: 8
    Last Post: 08-27-2006, 08:23 AM
  2. Craps Program with Local Variables
    By tigrfire in forum C Programming
    Replies: 12
    Last Post: 11-09-2005, 09:01 AM
  3. I need help with templates!
    By advocation in forum C++ Programming
    Replies: 6
    Last Post: 03-26-2005, 09:27 PM
  4. Conflicting types of typedef error
    By advocation in forum C++ Programming
    Replies: 4
    Last Post: 03-22-2005, 06:26 PM
  5. Huge variables
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 09-09-2001, 12:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21