basic C-programming Q

This is a discussion on basic C-programming Q within the C Programming forums, part of the General Programming Boards category; /* I'm new to this and am wondering why the output of this is what it is: */ int main() ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    2

    basic C-programming Q

    /* I'm new to this and am wondering why the output of this is what it is: */


    int main()
    {
    int number;
    number= 23 + 023 + 0x23;
    printf("The numbers: %d\n",number);
    }

    /* obviously "23" =23.
    I don't know why "023" = 19.
    I don't know why "0x23" = 35.

    Is there someone who can explain this concept for me?
    Thanks */

  2. #2
    ~- Y u n a -~ beely's Avatar
    Join Date
    Dec 2001
    Posts
    291

    Re: basic C-programming Q

    Originally posted by slyonedoofy
    /* I'm new to this and am wondering why the output of this is what it is: */


    int main()
    {
    int number;
    number= 23 + 023 + 0x23;
    printf("The numbers: %d\n",number);
    }

    /* obviously "23" =23.
    I don't know why "023" = 19.
    I don't know why "0x23" = 35.

    Is there someone who can explain this concept for me?
    Thanks */

    "0x23" == is hexdec.
    "023" == hexdec ? or octal (try to find out on calculator)

    two of the num change to decimal num and then sum up and store it on variable "number". that's all.

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    2
    Hey,
    thanks a bunch.
    now I got it.

    the 0x23 is hexidecimal (16*2)+3=35
    the 023 is octal (8*2)+3=19

    thanks for the help!
    Last edited by slyonedoofy; 10-30-2002 at 09:59 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 10:28 AM
  2. what are your thoughts on visual basic?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-22-2005, 05:28 AM
  3. visual basic vs C or C++
    By FOOTOO in forum Windows Programming
    Replies: 5
    Last Post: 02-06-2005, 08:41 PM
  4. Basic Graphics programming in C, please help
    By AdRock in forum Game Programming
    Replies: 3
    Last Post: 03-24-2004, 11:38 PM

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