I know the difference between new int()
and new int(10)
. In first case 0 is assigned and in second case 10 is assigned to newly created int. But what is the between new int {}
. We use {} for array initialization like new a[]{4,5,6}
. But for single variable what is the meaning of using braces while initializing?
/* Combined usage and initialized to 0*/
int *ptr2 = new int();
cout<<"*ptr2 = "<<*ptr2<<endl;
/* Allocated memory can be initialized to specific value */
int*ptr3 = new int(5);
cout<<"*ptr3 = "<<*ptr3<<endl;
int* ptr5 = new int{500};
cout<<"*ptr5 = "<<*ptr5<<endl;