Tony Tannous Tony Tannous - 1 year ago 114
C Question

Printf outputs nothing

I have to initialize a char array to 0's.

char array[256] = {0};

I wanted to check if it worked so I tried testing it

#include <stdio.h>

int main()
char s[256] = {0};
printf("%c\n", s[10]);
return 0;

After I compile it the command line shows nothing.

What am I missing ? Perhaps I initialized the array in a wrong manner ?

Answer Source

TL;DR -- %c is the character representation. Use %d to see the decimal 0 value.

Related , from C11, chapter ยง7.21.6.1, (emphasis mine)

c          If no l length modifier is present, the int argument is converted to an unsigned char, and the resulting character is written.

FYI, see the list of printable values.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download