int buf1[] = {0,0,0,0,0};
int* buf2 = new int[5]; //assume every element is initialzed to 0 as well
The only difference I can think of is buf1 is a reference to the array while buf2 is a pointer pointing to the array. In other words, buf1 always refers to the array while buf2 can point to other places as well.
Besides the mentioned one, is there any other difference between the two ways of declaring(and initializing an array)?
buf1is an automatic object (or static if it’s in the global scope);*buf2is a dynamic object. That is, the lifetime ofbuf1is controlled automatically, while the lifetime of*buf2is yours to manage. (buf2lives until you say something likedelete[] buf2;.)The initializers are also different;
buf1is brace-initialized, while*buf2is default-initialized (i.e. itsintelements are uninitialized).