The common cause of heap corruptions is the deletion of memory that was already deleted. I'll exemplify this scenario here:
1 2 3 4
int *p_memory(newint(10));
delete p_memory; // OK.
delete p_memory; // Not OK. 'p_memory' was already deleted.
Another scenario is when another pointer points to a region of memory allocated by some other pointer and then deletes it. For instance:
1 2 3 4 5
int *p_memory(newint(10));
int *p_handle(p_memory);
delete p_handle; // 'p_memory's memory has been deleted.
delete p_memory; // 'p_memory' was already deleted.
you're allocating only 3 char for name and the other data. That means if the user enters 3+ chars it's likely that it crashes because data is written beyond the end.
But I am not sure what kind of names and nationalities are 2-letter long (3 character array stores 2 letters and terminating null). Why not use strings?
But if I use
name=new char;
nationality=new char;
dateofbirth=new char;
then how to deallocate the memory in heap.......when I use
delete name;
delete nationality;
delete dateofbirth;
it gives me heap corruption error.............