Thread: variable garbage?

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    17

    variable garbage?

    Hi

    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?

    Thanks

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

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    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.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    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
    Server: irc.phoenixradio.org
    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
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    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, 03:31 PM
  2. Replies: 10
    Last Post: 09-27-2005, 12: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