Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22137

C: why printing a null char with %s prints "(null)"?

$
0
0

Why does printing a null char ('\0', 0) with %s prints the "(null)" string actually?

Like this code:

char null_byte = '\0';printf("null_byte: %s\n", null_byte);

...printing:

null_byte: (null)

...and it even runs without errors under Valgrind, all I get is the compiler warning warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat] (note: I'm using gcc 4.6.3 on 32bit Ubuntu)


Viewing all articles
Browse latest Browse all 22137

Trending Articles