Is memory allocation of statically allocated arrays always sequential in terms of address value?

Viewed 351

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 ?

1 Answers

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]
Related