Pointer Expressions



Like other variables, pointer variables can be used in expressions. For ex:–, if p1& p2 are properly declared & initialized pointers, then the following statements  are valid.

y=*p1 * *p2;

sum=sum + *p1;

*p2=*p2 + 10;

C allows us to add integers to or subtract integers from pointers, as well as to subtract one pointer from another.

P1+4, p2–2 & p1–p2 are all allowed. If p1&p2 are both pointers to the same array, then p2–p1 gives the no of else between p1& p2.

We may also use shorthand operators with the pointers.

P1++;
sum+=*p2;

Pointers can compared using the relational operators. The expressions such as

P1>p2, p1==p2, and p1!=p2 are allowed.

We may not use pointers in division & multiplication. Similarly 2 pointers cannot be added.

Related

C Language 7672438097827895938

Post a Comment

emo-but-icon

item