Pointer Expressions

We can use pointer variables in expression.

int x = 10, y = 20, z;
int *ptr1 = &x;
int *ptr2 = &y;
z = *ptr1 * *ptr2 ;
Will assign 200 to variable z.

We can perform addition and subtraction of integer constant from pointer variable.

ptr1 = ptr1 + 2;
ptr2 = ptr2 – 2;

We can not perform addition, multiplication and division operations on two pointer variables.

For Example:
ptr1 + ptr2 is not valid

However we can subtract one pointer variable from another pointer variable.
We can use increment and decrement operator along with pointer variable to increment or decrement the address contained in pointer variable.


We can use relational operators to compare pointer variables if both pointer variable points to the variables of same data type.


Pointer Increment and Scale Factor

We can use increment operator to increment the address of the pointer variable so that it points to next memory location.
The value by which the address of the pointer variable will increment is not fixed. It depends upon the data type of the pointer variable.
For Example:
int *ptr;

It will increment the address of pointer variable by 2. So if the address of pointer variable is 2000 then after increment it becomes 2002.
Thus the value by which address of the pointer variable increments is known as scale factor. The scale factor is different for different data types as shown below:


1 Byte


2 Byte

Short int

2 Byte

Long int

4 Byte


4 Byte


8 Byte

Long double

10 Byte

Download Projects

Download Programs