We can initialize the variable in two ways in C++11
One:
int abc = 7;
Two:
int ab
While for int
the existing replies are complete, I painfully found out, that in some cases, there are other differences between the ()
and {}
initializations.
The keyword is that {}
is an initializer list.
One such cases is, the std::string
initialization with count
copies of a char
:
std::string stars(5, '*')
will initialize stars
as *****
, but
std::string stars{5, '*'}
will be read as std::string stars(char(5), '*')
and initialize star as *
(preceded by an hidden character).