arr[0] = 1;
arr[2] = 2;
std::cout << *(arr + 1) << std::endl;
This is the output i got:
677446592
Since data in array are contiguous, why didn't I get 2?
your data is contiguos but the [1] element has no value set
Because you didn't set second element of an array
oh so space for it reserved?
its like if you try to do a print for int a; without setting the data
...so what am I shifting when I do "arr[1] =2", that makes the insertion time O(n)?
you are not inserting anything, you are setting the value of an element
This is undefined behavior, there is called stack redzone. It may contain garbage value from previous function. You are printing this garbage value.
Обсуждают сегодня