I have an assignment question that says "Decide whether the syntax of the following statements is valid or invalid."

These are the statements:

a)  listData->next = ptr1->next ;
b)  listData->next = *(ptr2->next) ;
c)  *listData = ptr2 ;
d)  ptr2 = ptr1->next->info ;
e)  ptr1->info = ptr2->info ;
f)  ptr2 = ptr2->next->next ;

where next is the address of the next object, and info is the data.

I see no syntax errors... what don't I understand? :(

Assignments can/should only be made between equivalent types. Follow the paths, there are some errors in there.

Can you assign the info member to a ptr? What to the couple of dereferencing actions do?

Pointer usage is one those areas where C/C++ give you lots of rope to shoot yourself in the foot.

Ok, so for example ptr->next can't be assigned ptr2->info ?

How about c)... listData is the starting pointer in the linked list. There's nothing wrong with this statement is there?

What does the * to to pointer listData? Does that give something that can be assigned a pointer value?

I don't think so? It's just a pointer to the first object in the linked list.

The objects contain a) data member (info) and b) address to next object (next).

I'm a little confused though, so I could be wrong?

Here are my updated answers.... I'm still not sure I quite understand this.

a.	OK
b.	Invalid; *(ptr2->next) is not a valid type for listData->next
c.	Invalid; listData cannot be de-referenced to accept a value of type pointer
d.	Invalid; ptr2 cannot be assigned a non-pointer value type
e.	OK
f.	OK
This article has been dead for over six months. Start a new discussion instead.