Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does `"%c"` exist in `printf` if `char` is converted to `int`?

In C you have the "%c" and "%f" formats flags for printf- and scanf-like functions. Both of these function use variable length arguments ..., which always convert floats to doubles and chars to ints.

My question is, if this conversion occurs, why do separate flags for char and float exist? Why not just use the same flags as for int and double?

Related question:
Why does scanf() need "%lf" for doubles, when printf() is okay with just "%f"?

like image 609
Paul Manta Avatar asked Jan 21 '12 09:01

Paul Manta


1 Answers

Because the way it gets printed out is different.

printf("%d \n",100); //prints 100
printf("%c \n",100); //prints d - the ascii character represented by 100
like image 184
Luchian Grigore Avatar answered Nov 06 '22 00:11

Luchian Grigore