Consider following program.
#include <iostream>
int main()
{
int a=int{};
std::cout<<a;
}
Is it uses aggregate initialization or default initialization? I am confused.
Empty parentheses or braces (T()
or T{}
) perform value initialization. The exception would be the case where the type is an aggregate in which case aggregate initialization would be used. Since int
is not an aggregate, it will be value initialized and since it's not a class nor an array, value initialization will do zero-initialization.
You were wondering why it doesn't work in C. Such syntax simply doesn't exist in C, see this answer.