C++ notations

Image for a hint

There are three types of notations in C++:

All of them are pretty same, but curly braces notation is a bit safer than other two. Assignment an functional notations allow narrowing conversion, that can be the reason of loosing data. Example:

int a = 5.6;
int b(6.6);
int c {7.6};

Despite difference between variable type and actual data type, a and b won't get any warning by compiler, and instead will be converted to 5 and 6 respectively, which is actually mentioned data loss. But on row with initializing c we'll get at least warning, or even an error in some compilers, that can help us to understand, that somewhere in come we might made a mistake, that leads to loosing some data.

#cpp #notations #curly #braces #narrowing
Vladyslav Serhiyev profile picture
Jun 02, 2021
by Vladyslav Serhiyev
Did it help you?
Yes !