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
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
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;
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.
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.
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.
ASKER
To lexpert,
It would help if I opened the question up to answers. Same as other comment I gave before.
It would help if I opened the question up to answers. Same as other comment I gave before.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I first had 10, but after reading your comment I see my mistake.
Looks mor like C++.
Anyway, what's the problem? So far it looks 'ok'