The following code shows bad memory access error (segmentation fault) when I run it. It does this right after it asks for name and the user has entered it. Help please:
Here you allocate a Person named Student. But nowhere do you allocate memory and set Student->MY_NAME to point to it. Consequently it is pointing to some random place in memory and, of course, your code does weird things when you access it.
1 2 3 4 5
struct Person
{
int AGE ;
Name MY_NAME ;
};
is probably more appropriate. Of course, there isn't much reason to be using dynamic memory in main, either.. and you don't use a corresponding delete for your new.
You would be better off with some constructors and destructors in your structs, so you can assign the required values to your member variables. Becuase the Name is declares on the heap inside the Person you need to ensure you release the memory allocated, hence the destructor. It is convention in c++ to use UPPERCASE variables for constants only.