Use new operator to initialise an array

This answer is useful 30

You can use memcpy after the allocation.

int originalArray[] ={1,2,3,4,5,6,7,8,9,10};
int *array = new int[10];
memcpy(array, originalArray, 10*sizeof(int) );

I’m not aware of any syntax that lets you do this automagically.

Much later edit:

const int *array = new int[10]{1,2,3,4,5,6,7,8,9,10};

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)