top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Can we add pointers together in C language?

+4 votes
445 views

Is it valid in C

P = P1 + P2 - P3 
posted Nov 13, 2013 by Jai Prakash

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

U can add a integer to a pointer like P1+10 is valid but P1 + P2 is not valid. But the thing you are trying to achieve can be achieved by the following way...

P = P1 + (P2 - P3)

assuming all pointers are of same type.

answer Nov 13, 2013 by Salil Agrawal
0 votes

It is not valid.

Since the pointer points address, if we add 2 address then resulting address may point to different segment or address. I guess this is the reason for this restriction.

answer Nov 13, 2013 by sivanraj
Similar Questions
+3 votes

I recently came to know about Restricted pointers in C. Can anyone throw some light on how and when is it used?

...