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;
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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
bufwill end up initialized to0.printfdoesn’t display anything becausebufis effectively a zero-length string.