Page 24 - PROGRAMMING IN C_Neat
P. 24
UNIT IV
1. Explain how pointers are declared and initialized. OR Write about pointers in detail. ***
Pointers:
Pointer – a variable that contains the address of another variable.
Example:
int a;
a = 6;
int *p;
p = &a;
Variable Declaration:
int a;
Memory Storage:
a Variable Name
1001 Variable Address
Variable Initialization:
a = 6;
Memory Storage:
a Variable Name
6 Value
1001 Variable Address
Address of Variable:
&a
where,
& - address operator
&a 1001 (address of a)
Pointer Variable Declaration:
int *p;
* is placed before the pointer variable.
Memory Storage:
a Variable Name
6 Value
1001 Variable Address
p Pointer Variable Name
2001 Pointer Variable Address
Pointer Variable Initialization:
p = &a;
Address of variable, a is assigned to pointer variable, p.