Link to home
Start Free TrialLog in
Avatar of netminder
netminder

asked on

Pointer Problem

I have this code where List and Ptr are pointers of type S*, struct S has members Data of type int, and Next of type S*
List=new S;
Ptr=new S;
Ptr->Data=10;
Ptr->Next=List;
Q=Ptr->Next;
Q->Data=20;
cout<<List->Data;

Since this involves pointers(which are very confusing), could anybody help me make this work.

Thanks
Avatar of KangaRoo
KangaRoo

cout <<
Looks mor like C++.

Anyway, what's the problem? So far it looks 'ok'
List=new S;
Ptr=new S;
Ptr->Data=10;
Ptr->Next=List;
Q=Ptr;                  //<--- This was error line, no Next needed
Q->Data=20;
cout<<List->Data;
Then you can just as well drop List as well... Q is equal to List in the Ex.
Avatar of netminder

ASKER

To lexpert,
I definetly phrashed what I was looking for incorrectly. Actually I need the result(cout), this way I can check to see if I did code it correctly. Post what you get for an result. I will then award points to u. Sorry for the confusion.
To lexpert,

It would help if I opened the question up to answers. Same as other comment I gave before.


ASKER CERTIFIED SOLUTION
Avatar of apmontgo
apmontgo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I first had 10, but after reading your comment I see my mistake.