When we create an array on stack , say int arr[20];
, is it guaranteed that each cell of the array is 4 bytes apart in the memory ? Or it might happen that some of the cells are not allocated sequentially ?
An array is guaranteed to be stored in contiguous memory. Pointer arithmetic is defined in such a way that
&arr[i] + 1 == &arr[i + 1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With