R
Roger
Can anyone tell me what is the difference between these two?
class nodeType
{
int data;
nodeType *link;
};
This is the first one:
main()
{
nodeType *test;
test->data=10;
cout << nodeType->data; // 10
}
and this is the second one:
main()
{
nodeType *test=new nodeType;
test->data=10;
cout << test->data; // 10
}
I am kind of confused because the first one was given by my instructor.
How is the memory allocated in the first situation?? Is there any
benefit or drawback of not using dynamic memory allocation??
Thanks in advance.
class nodeType
{
int data;
nodeType *link;
};
This is the first one:
main()
{
nodeType *test;
test->data=10;
cout << nodeType->data; // 10
}
and this is the second one:
main()
{
nodeType *test=new nodeType;
test->data=10;
cout << test->data; // 10
}
I am kind of confused because the first one was given by my instructor.
How is the memory allocated in the first situation?? Is there any
benefit or drawback of not using dynamic memory allocation??
Thanks in advance.