Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What does this line of code do?
C
p->next->next


what about this one:


C
p->next->data


SOrry if i did anything wrong 1st time.
Posted
Updated 4-Jun-13 13:11pm
v2

p->next->next

In this case we are traversing the linked list.
We are basically navigating two link nodes.
p->next->data

Here, we are navigating to the next linked list node and then accessing its data value.
 
Share this answer
 
Comments
iiREDii 4-Jun-13 9:38am    
i made a drawing:http://i39.tinypic.com/a9lpva.png so using that pic tell me where do these 2 lines take me if at first the pointer is at the head of the list.
P.S:dont laugh at my drawing skillz please......
CPallini 4-Jun-13 10:52am    
My 5.
Abhinav S 4-Jun-13 22:27pm    
Thanks.
[no name] 7-Jun-13 1:13am    
My too 5.
Abhinav S 7-Jun-13 5:49am    
Thank you.
Quote:
p->next->next
See it as a two-steps operation:
C
p->next

gives you the pointer to the next element of the list, then
C
(p->next)->next

gives you the pointer to the element immediately following the next, that is the pointer to the item 'at distance 2'.


Quote:
p->next->data
With a similar argument, you may write
C
(p->next)->data

showing you are accessing the data member of the next element of the list.
 
Share this answer
 
Comments
Abhinav S 4-Jun-13 9:45am    
5.
iiREDii 4-Jun-13 10:37am    
yeah thats where normal logic took me,look at the pic i posted on solution 1 below could you do another pic using arrows to explain me where do both lines take you to?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900