4. 34 35
3
a
Base address or
address of
memory block
Name of memory
block or variable
name
Content on
memory block
5. 34 35
3
a
Base address or
address of
memory block
In pointers we
shall deal with
address of the
memory block
6. Definition of Pointer
• Pointer is a special kind of variable which can contain address of
another variable of same data type.
Declaration of Pointer
int *x;
Initialization of Pointer
x=&a;
7. 54 55
34
xa
34 35
3
void main()
{printf(“ %d n ”, &a);
printf(“ %d n ”, x);
printf(“ %d n ”, &x);
printf(“ %d n ”, *x);
printf(“ %d n ”, *&a);
printf(“ %d n ”, *&x);
}
34
34
54
3
3
34
8.
9. To store the address of any longer variable we
have to declare a double pointer.
int **y;
which can store the address of pointer variable x;
y=&x;
int ***z;
z=&y;
z is for store the address of y and so on.
10. Pointer always consumes 2 bytes memory
• According to Dos Based architecture a C program consumes 16 kb or
65536 bytes of memory means in unsigned binary it is
1111111111111111 (16 times 1) and so the maximum address may be
65535 and 2 bytes are sufficient to store it.
11. Arithmetic operations for pointers
• We can’t add, divide or multiply two address.
• We can subtract two address of same data type.
int a,b;
//&a-&b= (&a-&b)/sizeof(a)
• We can’t divide or multiply an integer to a pointer.
• We can add and subtract an integer to a pointer.
12. Arithmetic operations for pointers
int *y , a = 3;
y = &a;
y = y + n;
y = y - n;
/*
: y = y + n;
: y = y + sizeof(datatype of y)*n;
: y = y - n;
: y = y - sizeof(datatype of y)*n;
*/
13. Key facts about Pointers
• For printing any address we should use %u instead of %d in printf()
function.
Because Range of %d is -32768 to 32767 and %u is 0 to 65535
• & is Known as address of or referencing operator. It takes variable and
return its address. It is unary operator. &a is used to represent the
address of block x.
• * is Indirection or dereferencing operator. It takes address and gives
value on that address. It is also unary operator.
• Pointer When incremented, always point to immediately next block of
its own type.