Jump to content
Sign in to follow this  
Guest JoeB

Adding To A Pointer

Recommended Posts

Guest JoeB

The compiler should handle the addition before assignment.

 

both these statments should be equal, but (in the simulator) they are not:

 

x = *pText + 1;

 

x = *(pText + 1);

 

 

The second statment gives the expected result (get data from the space after pText) whereas the 1st gives garbage.

 

 

 

-- I may be wrong...

Share this post


Link to post
Share on other sites
The compiler should handle the addition before assignment.

 

both these statments should be equal, but (in the simulator) they are not:

 

x = *pText + 1;

 

x = *(pText + 1);

 

 

The second statment gives the expected result (get data from the space after pText) whereas the 1st gives garbage.

 

 

 

-- I may be wrong...

 

* has precedence over +.

The first statement gets what pText is pointing to and adds 1 to it.

Share this post


Link to post
Share on other sites
-- I may be wrong...

 

This is not an error. Picxie is correct. The first expression gets content of pText and adds 1 to it and the second gets the content of pText+1 location.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...