Page 26 - PROGRAMMING IN C_Neat
P. 26
*p gives the value of a[0].
*(p+1) gives the value of a[1].
.
.
.
*(p+n) gives the value of a[n].
Example:
static int a[3] = {10, 20, 30};
int *p;
Memory Storage:
p
a[0] a[1] a[2]
10 20 30
100 102 104
Base Address &a[0] = 100.
p = &a[0];
The address of a[0] is assigned to the pointer variable, p. p = 100.
p = &a[0];
p++;
p++ p = p+1
p = p + 1*ScaleFactor
p = p + 1*2 (ScaleFactor for integer = 2)
p = 100 + 2
p = 102
p = &a[0];
q = *(p+1);
The value of a[1] is stored in q. q = 20.
_______________________________________________________________________________________
4. Explain pointers and two dimensional array. ***
Pointers and Two Dimensional Array:
Example:
static int a[2][2] = { {10, 20}, {30, 40} };
int *p;
p = &a[0][0];
Memory Storage - Logical View:
0 1
10 20
0
30 40
1