If you declare array a[4]
, it means it has 4 elements.
The only valid indicies are a[0]
, a[1]
, a[2]
, and a[3]
.
Accessing a[4]
is invalid.
I don’t know why you think a[4
] would have 5 elements in it.
This array has 4 elements, and its size is:
4-elements * 4-bytes = 16 bytes.
More Related Contents:
- how do arrays work internally in c/c++
- What is the difference between '.' and '->' when used in array? [closed]
- What is array to pointer decay?
- determine size of array if passed to function
- May I treat a 2D array as a contiguous 1D array?
- C++ pass an array by reference
- How does delete[] know it’s an array?
- Pointer address in a C multidimensional array
- C/C++ int[] vs int* (pointers vs. array notation). What is the difference?
- Difference between pointer to a reference and reference to a pointer
- Declare large array on Stack
- C++ correct way to return pointer to array from function
- Create new C++ object at specific memory address?
- pointer to array c++
- Store an int in a char array?
- Pointer-to-pointer dynamic two-dimensional array
- Could I ever want to access the address zero?
- How to make an array with a dynamic size? General usage of dynamic arrays (maybe pointers too)? [closed]
- Are non dereferenced iterators past the “one past-the-end” iterator of an array undefined behavior?
- can’t modify char* – Memory access violation
- Can I Allocate a specific memory address using pointers in c++?
- Dereferencing deleted pointers always result in an Access Violation?
- Why are `&array` and `array` pointing to the same address?
- How do I create an array of pointers?
- array decay to pointer and overload resolution
- In C/C++, is char* arrayName[][] a pointer to a pointer to a pointer OR a pointer to a pointer?
- Function returning array but main showing garbage [duplicate]
- difference between pointer to an array and pointer to the first element of an array
- How can a char pointer be initialized with a string (Array of characters) but an int pointer not with an array of integer? [duplicate]
- int *array = new int[n]; what is this function actually doing?