| Like other variables pointer variable can also be used in expressions. Arithmetic and comparison operation can be performed on the pointers. |
| |
| Pointer Arithmetic |
| |
| Example: |
| |
| Addition of a number to a pointer int i=4,*j,* |
| |
| j=&i; |
| j=j+1; |
| j=j+9; |
| k=j+3; |
| |
| Example: |
| |
| Subtraction of number from a pointer int i=4,*j,*k; |
| |
| j=&i; |
| j=j-2; |
| j=j-5; |
| k=j-6; |
| |
| But the following operation are not allowed on pointers: |
| |
| a) multiplication of pointer with a constant |
| |
| b) addition of two pointer |
| |
| c) division of pointer with a constant |
| |
| Pointer Comparison |
| |
| Pointer can be compared using relational operator. Expression such as- p1>p2 p1=p2 p1!=p2 are allowed. |
Other Recommended Posts on C programming
Post a Comment