1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

I'm a beginner

Discussion in 'C' started by djerry, Dec 2, 2008.

  1. djerry

    djerry New Member

    Joined:
    Dec 2, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hi everybody!
    i'm a beginner in c++ and when i was studying i found a problem. I didn't understand what for is the int command if someone of you could please anwer this i'll be very gratefull :)
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    It defines a variable of type integer, which stores positive and negative whole numbers within a specific limit.

    That limit is machine dependent but typically it's from -2^31 up to +2^31-1. ^ means "to the power of", so that's -2147483648 to +2147483647 (notice it's not symmetrical, that's because there's only one representation for zero).

    Examples:

    int foo; // defines an integer variable called foo with an undefined initial value. You have to watch uninitialised variables carefully to avoid some possibly difficult to find bugs (e.g. the program works in a "debug" compile but not in a "release" compile, which is VERY annoying!).

    int bar=-27; // defines an integer bar containing the initial value of -27. Always initialise variables! Even if just to zero.

    int quux=9999999999; // invalid, because 9,999,999,999 is greater than the maximum value you can store (2,147,483,647). You should get an error, or at least a warning, if you try to compile this one.

    int gronk=3.14159265; // invalid, because pi isn't a whole number. This may or may not throw an error; if not, it will assign 3 to gronk. You may get a compiler warning.
     
    shabbir likes this.
  3. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    734
    Likes Received:
    37
    Trophy Points:
    0
    [COMMENT]I would not like to post if your Title does not speak what it contains inside and so try giving Good Titles.[/COMMENT]
     

Share This Page