what is the difference between %# and % in printf

This is a discussion on what is the difference between %# and % in printf within the C Programming forums, part of the General Programming Boards category; printf ("Some different radixes: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100); %x shows 100 in hexadecimal ...

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    what is the difference between %# and % in printf

    printf ("Some different radixes: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100);

    %x shows 100 in hexadecimal basis

    64

    but %#x makes some memory address out of it

    0x64


    what does the addition of # ???

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    That's why you go to your friendly terminal screen and type man printf(or google, or the C standard, or heaven forbid, your textbook) and find this:
    Quote Originally Posted by ISO C, 7.19.6.1
    # The result is converted to an ‘‘alternative form’’. For o conversion, it increases
    the precision, if and only if necessary, to force the first digit of the result to be a
    zero (if the value and precision are both 0, a single 0 is printed). For x (or X)
    conversion, a nonzero result has 0x (or 0X) prefixed to it. For a, A, e, E, f, F, g,
    and G conversions, the result of converting a floating-point number always
    contains a decimal-point character, even if no digits follow it. (Normally, a
    decimal-point character appears in the result of these conversions only if a digit
    follows it.) For g and G conversions, trailing zeros are not removed from the
    result. For other conversions, the behavior is undefined.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. wats the fault...
    By ElemenT.usha in forum C Programming
    Replies: 17
    Last Post: 01-04-2008, 01:52 PM

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