Thread: basic doubt

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    6

    Unhappy basic doubt

    hi,

    Code:
    void main()
    {
    printf("%d",'\65');
    }
    why does this print 53?

    Thanks
    Vikranth.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    This is a question on a test/assignment or similar, isn't it?

    What do you THINK it should print? What do you know about the meaning of '\nnn' character forming?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    6
    Hi Mats,

    i havent cum across that \nn formatting

    can u please tell me how it works??

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, explain to me what you THINK it does. f you don't know at all, perhaps you can look up "character constants" in your C book?

    Just to clarify your "doubt" - there is no doubt here: the code is doing exactly what it should - it is only "unexpected" if you don't quite understand what the form of '\nnn' is doing.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    6
    Quote Originally Posted by matsp View Post
    So, explain to me what you THINK it does. f you don't know at all, perhaps you can look up "character constants" in your C book?

    Just to clarify your "doubt" - there is no doubt here: the code is doing exactly what it should - it is only "unexpected" if you don't quite understand what the form of '\nnn' is doing.

    --
    Mats
    i dont know what this '\' does in the printf?? i saw in ansi c book but it doesnt explain about the situation like this : printf("%d",'\65');

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ok, so if we have:
    Code:
    int x = '\65';
    does that simplify things?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Oct 2007
    Posts
    4
    Hi

    \ddd where ddd is octal here.So u can use only the numbers from 0-7
    And the logic is octal numbers are converted back to int(base 10) when printing.
    Hope this helps

    Praveen SP

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > void main()
    If your book told you to do this, you need a different book.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. function calling: basic doubt
    By doubty in forum C Programming
    Replies: 10
    Last Post: 06-23-2009, 02:31 AM
  2. basic doubt
    By sincere_cute in forum C Programming
    Replies: 2
    Last Post: 06-20-2007, 03:33 AM
  3. [B]a basic doubt !![/B]
    By samirself in forum C Programming
    Replies: 6
    Last Post: 04-30-2005, 01:39 PM
  4. basic doubt in pointer concept
    By sanju in forum C Programming
    Replies: 1
    Last Post: 10-24-2002, 11:35 PM