On another SE site I saw code similar to this:
int x[] = {1,2,3,4};
....
x[0] = {99};
For the assignment, is there an advantage to this over simply:
x[0] = 99;
On another SE site I saw code similar to this:
int x[] = {1,2,3,4};
....
x[0] = {99};
For the assignment, is there an advantage to this over simply:
x[0] = 99;
Yes, there is one.
Those brackets disable implicit narrowing conversions, so if the type of the expression inside does not fit an int
it's an error instead of a silent loss of data.
Of course, 99
is plenty small and thus of type int
.
Try it with a sufficiently large literal like 99999999999
: http://ideone.com/D89wVx