int a[]={};
The program is ill-formed. There may not be arrays of size zero with local (or static) storage. (Dynamic arrays of zero size are allowed, though I haven't found use for them).
am I getting into undefined behaviour
a[0] = 5;
a[1] = 6;
You access elements outside the bounds of the array. The behaviour of the program is undefined.
Adding to an Array
Can I add to an array...?
It is not possible to add elements to an array. The size of an array remains constant throughout its entire lifetime.
What you can do is dynamically create a new array that is larger, and copy the elements from the old array to the new one. There is a standard container that implements this: std::vector
.