C-Style One-Dimensional Arrays:
- Boundary checking:
C++ (or C) does not check an array index to ensure that it belongs to the range for which the array is defined.
☺Some Important points:
list[5]: five integers
list[0], list[1], list[2], list[3], list[4]
*plist[5]: five pointers to integers
plist[0], plist[1], plist[2], plist[3], plist[4]
- implementation of 1-D array
list[0] base address = a
list[1] a + sizeof(int)
list[2] a + 2*sizeof(int)
list[3] a + 3*sizeof(int)
list[4] a + 4*size(int)
- Compare int *list1 and int list2[5] in C.
- Same: list1 and list2 are pointers.
- Difference: list2 reserves five locations.
- Notations:
- list2 - a pointer to list2[0]
- (list2 + i) - a pointer to list2[i] (&list2[i])
- *(list2 + i) - list2[i]
No comments:
Post a Comment