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

What are Keywords & Identifiers?

Every C word is classified as either a keyword (or) identifier. Keyword : There are certain reserved words called keywords. All key words have fixed meanings & these meanin...

What is Character Set of 'C'?

Characters that can be used to form words, numbers & expressions depend upon the computer on which the program is run. The characters in C are grouped into the following categories: 1. le...

Executing a ‘C’ Program

Executing a program written in C involves a series of steps: these are 1. Creating a program. 2. Compiling the program Alt + F9. 3. Linking the program with functions that are needed from t...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item