Doubt in a concept

Sir, I had a confusion.
when i intialise like int* a=new int[5]{0}, all elements are initialized to 0 but when I initialse like int* a= new int[5]{2}, all the elements do not get initialised to 2

yes
this concept is not only limited to dynamic memory allocation

also valid on any type of array initialization

int arr[5]={1,2};

first two elements will be 1 and 2 rest are 0

int arr[5]={0};
all element are initialized with 0

int *a =new int [5]{}

inside braces you have to pass the initial value of array if don’t pass it assume them to 0

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.