Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

What is the difference between %# and % in printf

  1. Oct 8, 2008 #1
    printf ("Some different radixes: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100);

    %x shows 100 in hexadecimal basis


    but %#x makes some memory address out of it


    what does the addition of # ???
  2. jcsd
  3. Oct 8, 2008 #2

  4. Oct 8, 2008 #3
    regarding this
    "For 'o', 'x', and 'X', a 0, 0x, and 0X, respectively, is prepended to non-zero numbers."

    X turns to hex basis and O to octal basis
    i was told that when we add # it add 0X to the transformed basis number in hex basis
    but in octal basis it adds 0

    "Used with o, x or X specifiers the value is preceeded with 0, 0x or 0X respectively for values different than zero."

    for what values we have different added signs???

    g is a small float number

    the trail of zeros you mean
    0.765000000 >>0.765

    Last edited: Oct 8, 2008
  5. Oct 8, 2008 #4
    Prepending 0 -- like 0123 -- indeed causes a literal value to use octal basis.

    Prepending 0x -- like 0x0123 -- causes a literal value to use hex basis.

    As far as I know prepending x (x0123?) doesn't do anything. I could be wrong.

    I assume the reason they prepend 0 in octal and 0x in hex is because in both cases they're trying to reproduce the string necessary in order to create a literal if you paste the value back into C directly.

    I wouldn't worry too much about the %# badge, I don't think many people use it. I've personally actually never used it before in my life, when I want to prepend 0x I just, you know, prepend 0x...

    I don't know exactly what they mean by "trailing zeroes". I'd suggest just trying it and seeing what happens if you're really curious.

    Don't understand the question
  6. Oct 8, 2008 #5
    thanks i understand know
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: What is the difference between %# and % in printf
  1. Printf debugging (Replies: 3)

  2. Printf question (Replies: 10)