Code: Select all
char buf1[256];
char buf2[256] = "";
Moderator: Moderators
Code: Select all
char buf1[256];
char buf2[256] = "";
News to me. I though I had to do ALWAYS one of these 2 ways...tepples wrote:It allocates an array of 256 elements of type char, whose data is initialized to the empty string.
Code: Select all
1. memset(buf,0,256);
2. int i=0;
for(i=0;i<256;i++) buf[i]=0;
Code: Select all
char memory[0x2000] = {0};
It's been there since at least C89:Drag wrote:Was that always there or is it a recent addition?
ansi.c.txt wrote:3.5.7 Initialization
...
If an object that has static storage duration is not initialized
explicitly, it is initialized implicitly as if every member that has
arithmetic type were assigned 0 and every member that has pointer type
were assigned a null pointer constant.
...
If there are fewer initializers in a list than there are members of
an aggregate, the remainder of the aggregate shall be initialized
implicitly the same as objects that have static storage duration.
Code: Select all
uint8_t buf[256] = {};