Why does `printf(“%c”, 5)` print a vertical bar?

  • A+

Here is the code

#include <stdio.h>  int main() {     printf ("/t%d/n",printf("MILAN"));     printf ("/t%c",printf("MILAN")); } 

Here is the output

$gcc -o main *.c $main 



Now the question is

Why printf return | when we are printing characters (formatter as %c) ?

What is the relation between 5 and | here?


Your question really boils down to the behaviour of printf("%c", 5);.

The actual output is a function of the character encoding used by your platform. If it's ASCII (very common) then it will output the control character ENQ. What you actually get as an output will depend on your command shell, and a vertical bar is not an unreasonable choice.


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: