variable garbage?

This is a discussion on variable garbage? within the C++ Programming forums, part of the General Programming Boards category; Hi I haven't initialised a variable, and so the value I'm getting from it is some floating point number? I ...

  1. #1
    Registered User
    Join Date
    Nov 2003

    variable garbage?


    I haven't initialised a variable, and so the value I'm getting from it is some floating point number? I know this is because I haven't initialised it, but why does it contain a floating point number?


  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    It contains whatever was in memory before your program was run...maybe code...maybe other variables....maybe Bill Gate's phone way to know unless you get dialling!

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Because the variable type you declared is floating point, the bits in that memory location are just interpreted as a floating point number. Remember, all variables are is just bits, plain and simple.
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ

  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    it could actually be some of your post in this thread... the bits are just read as a float instead of chars...
    Join is in our Unofficial Cprog IRC channel
    Channel: #Tech

    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  5. #5
    Cat is offline
    Registered User
    Join Date
    May 2003
    Yes, it's impossible for a float or double to contain anything besides a float or double -- whatever those 32 or 64 bits contain, it will be interpreted as a floating point. Technically I suppose you could get NaN as well, but the odds of that are very small.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. static class variable vs. global variable
    By nadamson6 in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2005, 04:31 PM
  2. Replies: 10
    Last Post: 09-27-2005, 01:49 PM
  3. static variable
    By Roaring_Tiger in forum C Programming
    Replies: 9
    Last Post: 04-01-2003, 01:12 PM
  4. Need help
    By awkeller in forum C Programming
    Replies: 2
    Last Post: 12-09-2001, 03:02 PM
  5. Variable Allocation in a simple operating system
    By awkeller in forum C Programming
    Replies: 1
    Last Post: 12-08-2001, 02:26 PM

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