I would like to know if there is a difference between:
char s[32] = "";
and:
char s[32] = {0};
Thanks.
Is there any case when the sign before 0 matters? In mathematics +0 is a value just a little greater than 0 . Also, -0 is a value just a little lower than 0 . For example: n / Infinity would return +0 and n / -Infinity -0 (supposing that n is a real number greater than 0).
Here is how Wikipedia explains signed zeroes: “Signed zero is zero with an associated sign. In ordinary arithmetic, the number 0 does not have a sign, so that −0, +0 and 0 are identical.
Depending on local conventions, zero may be considered as being neither positive nor negative (having no sign or a unique third sign), or it may be considered both positive and negative (having both signs).
There are many differences between one and zero. For one, (haha, get it, one) zero is neither positive nor negative while one is positive. Another difference would be that one is the multiplicative identity, while zero is the additive identity. Also, any 1 to any power is 1, while any 0 to any power is 0.
The standard way of telling a letter O from a number 0 in handwriting is to put a slash through the number. If you're writing a question or answer it is the "Preformatted text" button (looks like { } ). Or you can just indent the line 4 spaces. To make some inline c0d3 surround the text with backticks (``).
Dear student, The difference of any given number and 0 is always the number itself. See in the example:- (2-0) =2 , (15-0) =15 so difference of any given number with 0 is the number itself.
No there is no difference between both declarations:
char bla[32] = {0};
and
char bla[32] = "";
See the relevant paragraph of the C Standard (emphasis mine):
(C99, 6.7.8p21) "If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration."
In that case, there's no difference, both initialise all slots of the array to 0. In general, ""
works only for char
arrays (with or without modifications like const
or unsigned
), but {0}
works for arrays of all numeric types.
In section 6.7.9 of the standard (n1570), point 21 reads
If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration.
so even ""
initialises the complete array.
The result of both expressions is the same: an empty string. However, the first is more explicit, thus more readable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With