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;


  • I think this might prevent implicit narrowing conversions, but for an int literal it's going to be absolutely irrelevant. – amon Jun 15 '17 at 12:32

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.