Math, asked by divesh4952, 1 year ago

what arithmetic operations are aowed in pointers

Answers

Answered by Anonymous
2
Hey !

Here is your answer.........

_______________________________

We can't perform every type of arithmetic operations with pointers.

Pointer arithmetic is slightly different from arithmetic we normally use in our day to day life.

The only valid arithmetic operations applicable on pointers are:

1) Addition of integer to a pointer

2) Subtraction of integer to a pointer

3) Subtracting one pointer from another of the same type

The pointer arithmetic is performed relative to the base type of the pointer.

-------------------------------------------

For example:

if we have an integer pointer ip which contains address 1000, then on incrementing it by 1, we will get 1004 (i.e 1000 + 1 * 4) instead of 1001 because the size of the int data type is 4 bytes.

If we had been using a system where the size of int is 2 bytes then we would get 1002 ( i.e 1000 + 1 * 2 ).

Similarly, on decrementing it we will get 996 (i.e 1000 - 1 * 4) instead of 999.

So the expression ip + 4 will point to address 1016 (i.e 1000 + 4 * 4 ).

______________________________________________________________

HOPE THIS ANSWER WILL HELP U......
Similar questions