What does char buf[MAXDATASIZE] = { 0 };
's {0}
means?
tried to print it out but it print nothing.
#include <stdio.h>
int main(void)
{
char buf[100] = { 0 };
printf("%s",buf);
return 0;
}
c++
What does char buf[MAXDATASIZE] = { 0 };
's {0}
means?
tried to print it out but it print nothing.
#include <stdio.h>
int main(void)
{
char buf[100] = { 0 };
printf("%s",buf);
return 0;
}
Best Answer
This is just an initializer list for an array. So it's very like the normal syntax:
However, the C standard states that if you don't provide enough elements in your initializer list, it will default-initialize the rest of them. So in your code, all elements of
buf
will end up initialized to0
.printf
doesn't display anything becausebuf
is effectively a zero-length string.