- Arrays and pointers closely related
–Array name like a constant pointer
–Pointers can do array subscripting operations
–Pointers can do array subscripting operations
- Declare an array b[5] and a pointer bPtr
bPtr = b;
Array name actually a address of first element
OR
bPtr = &b[0]
Explicitly assign bPtr to address of first element.
Array name actually a address of first element
OR
bPtr = &b[0]
Explicitly assign bPtr to address of first element.
- Element b[n]
–can be accessed by *( bPtr + n )
–n – offset (pointer/offset notation)
–Array itself can use pointer arithmetic.
b[3] same as *(b + 3)
–Pointers can be subscripted (pointer/subscript notation).
bPtr[3] same as b[3].
–n – offset (pointer/offset notation)
–Array itself can use pointer arithmetic.
b[3] same as *(b + 3)
–Pointers can be subscripted (pointer/subscript notation).
bPtr[3] same as b[3].
No comments:
Post a Comment