I've started learning c++ from learncpp.com.
In second lesson where functions are explained, there is a strange variable initialization in the first example: int input{ 0 };
My IDE (CLion) claims: > Expected ";" at the end of declaration.
If I run this code (using gcc), it works well. Same if I remove the parentheses.
So what's the meaning of {}
after the variable name?
Here is the full example:
#include <iostream>
int getValueFromUser()
{
std::cout << "Enter an integer: ";
int input{ 0 };
std::cin >> input;
return input;
}
int main()
{
int num { getValueFromUser() };
std::cout << num << " doubled is: " << num * 2 << '\n';
return 0;
}