What will be the output of this? Please explain it also [closed]

Apparently your a variable was initialized with 0.

  • %u displays an unsigned integer, and you pass the memory address as an argument
  • %p usually displays the value of a pointer, so in case of 0 it shows it as (nil)
  • %p does the same, but you now pass the address of a, which is displayed in hex.
  • %fp is %f (float formatting) and a literal p. I’m pretty sure this one causes undefined behavior since printf expects a float and you pass an integer (pointers are long/integer values).

What do we learn from it? Don’t write nonsense code and don’t pass arguments to printf-style functions unless you have a format string that expects exactly those arguments.

Leave a Comment