C++ notations
There are three types of notations in C++:
- assignment notation (
int a = 5); - functional notation (
int a(5)); - curly braces notation (
int a {5}).
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.