Jump to content

Adding To A Pointer


Guest JoeB

Recommended Posts

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...

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.

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...
×
×
  • Create New...