In C, pointer holds address of a value, so there can be arithmetic operations on the pointer variable. Following arithmetic operations are possible on pointer in C language:
1. Increment/addition
2. Decrement/subtraction
1. Increment:
It is used to increment the pointer. Each time a pointer is incremented, it points to the next location with respect to memory size.
Example,
If ptr is an integer pointer stored at address 1000, then ptr++ shows 1002 as incremented location for an int. It increments by two locations as it requires two bytes storage.
OR
1. Addition
When addition operation is performed on pointer, it gives the location incremented by the added value according to data type.
Example:
If ptr is an integer pointer stored at address 1000, Then ptr+2 shows 1000+(2*2) = 1004 as incremented location for an int.
0 Comments