top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

Can we add pointers together in C language?

+4 votes
62 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 Google+ Share Button LinkedIn Share Button Multiple Social 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?

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...