what this line will do?
char var[] = {0};
Is this equivalent to the following?
char var[1];
memset(var, 0, NULL);
what this line will do?
char var[] = {0};
Is this equivalent to the following?
char var[1];
memset(var, 0, NULL);
char var[]
will define var
as a char array where size is decided by the initializer list size.
So char var[] = {0}
is equivalent to char var[1] = {0}
.
In your later code snippet, var
may be uninitialized first (if a local variable, which I believe it is as it is followed by memset
) and is then set to all zeros.(assuming you meant memset(var, 0, 1)
) Although the observable effect of the both snippets are same, compiler may generate different instructions or compiler may choose to call the memset
which may add function call overhead in later snippet.