I'm trying to make a simple linked list example. I am using the dynamic method of memory allocation.
#include <iostream.h>
struct node
{
int INSTRUCTION;
node * next;
node()
{ next = NULL; INSTRUCTION = 0; }
void setnext(node *P)
{ next = P; }
void DELETE()
{ delete this; }
};
void main()
{
node *A = new node();
node *B = new node();
A->setnext(B);
B->setnext(NULL);
cout << &A << endl << A->next << endl << &B << endl << B->next;
delete A, B;
}
In the code, &B and A->next should have the same value, but for some reason I am getting different addresses printed on the screen.