Thread: Newbie Question integers and variables

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    4

    Newbie Question integers and variables

    Hi all!

    I'm a newbie and wonder why:

    int a, b, c;
    a = 5;
    b = 12000;
    c = a*b;
    printf("%d", c);

    does not yield 60000

    Please help!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Um, it looks okay to me.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    60000 is probably to big for an integer to hold on your system. Use a long int instead, and write
    Code:
    printf("%ld", c);
    to specify a long digit.

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    4
    Ah, that makes sense. I thought an integer could hold higher numbers... guess it does depend on the system and/or the compiler...

    Thanks!

  5. #5
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    BTW what complier/os are you using?
    Woop?

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    4
    The thing is, I'm not, but I have this "study" question that asked this question and I couldn't figure out why.... it wasn't suppose to work...

  7. #7
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Very sneaky way to get people to do your work GJ
    Woop?

  8. #8
    Registered User
    Join Date
    May 2006
    Posts
    4
    yeah.... now I have a different problem I have no answer to...... maybe you could answer exactly what this function does with the string...

    Code:
    void foo(char *string, int length)
    {
      char temp;
    
      if(length < 2)
        return;
      else {
        temp = *string;
        *string = string[length - 1];
        string[length -1] = temp;
        foo(string+1, length-2);
      }
    }

  9. #9
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    it recursively reverses the characters in the string. If this is homework, read the board policy.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by MrMe
    yeah.... now I have a different problem I have no answer to...... maybe you could answer exactly what this function does with the string...
    I've got a better idea. Make a test program, stick the function in it, and find out for yourself.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  2. Reading Separate Digits as Variables
    By linuxpyro in forum C Programming
    Replies: 7
    Last Post: 09-13-2006, 05:23 PM
  3. Declaring Variables for Arrays~ Newbie Question
    By sashax415 in forum C++ Programming
    Replies: 2
    Last Post: 12-17-2005, 05:27 PM
  4. This should be an easy question...
    By Razorblade Kiss in forum C++ Programming
    Replies: 16
    Last Post: 01-07-2005, 10:55 PM
  5. Scanning integers from a file:
    By xarmenx in forum C Programming
    Replies: 6
    Last Post: 11-29-2004, 04:57 PM