Page 27 - PROGRAMMING IN C_Neat
P. 27
Memory Storage - Physical View:
Pointer Expression p p+1 p+2 p+3
a[0][0] a[0][1] a[1][0] a[1][1]
10 20 30 40
Address 100 102 104 106
Base Address 100.
Address Calculation:
Formula:
Address of a[i][j] = p + [(n*i) + j]
n – no. of columns.
Address of a[0][1] = p + [(2*0) + 1]
= p + 1
= p + 1*ScaleFactor
= p + 1*2 (ScaleFactor for integer = 2)
= 100 + 2
= 102
Value of a[0][1] = *(p + 1)
= 20
_______________________________________________________________________________________
5. Explain array of pointers to strings with an example. ***
Array of Pointers to Strings:
Example:
static char *p[3] = {“Kandan”, “Kumaran”, “Velan”};
Array, p has 3 pointers.
Each pointer points to a string.
Memory Storage:
p[0] K a n d a N \0
p[1] K u m a r A n \0
p[2] V e l a n \0
_______________________________________________________________________________________________
6. Explain pointers as function arguments with example. OR Explain how pointers are used as function
arguments with example. ***
Pointers as Function Arguments:
Pointers can be used to pass addresses (references) to a function’s formal arguments.