I have to initialize a char array to 0's. I did it like
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 and run it, the command line output shows nothing.
What am I missing ? Perhaps I initialized the array in a wrong manner ?
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 nol
length modifier is present, theint
argument is converted to anunsigned char
, and the resulting character is written.
FYI, see the list of printable values.
That said, for a hosted environment, int main()
should be int main(void)
, at least to conform to the standard.