+ 1

What is int k{1}; in c++ ?

1st Nov 2017, 3:24 PM
Jan Moravec
Jan Moravec - avatar
5 odpowiedzi
+ 3
That is a new way to initialize variables in C++11.
1st Nov 2017, 5:15 PM
Bob
Bob - avatar
+ 4
In C++11 you can use int k{}; instead of int k = 0;. int k{}; may not work unless C++11 standard is enabled.
1st Nov 2017, 5:24 PM
Bob
Bob - avatar
+ 3
It would. The example in my lessons is vector<int> number {6, 5, 4, 3}; cout << number [2]; I'm not sure on the array initialization. I don't have C++11 on my mobile to test it.
1st Nov 2017, 5:46 PM
Bob
Bob - avatar
+ 2
It is equivalent to "int k = 1;" in this context.
1st Nov 2017, 3:50 PM
aklex
aklex - avatar
+ 1
thanks for the explanation guys :)
1st Nov 2017, 6:41 PM
Jan Moravec
Jan Moravec - avatar