Why does this basic C++ program gets stuck after completion, it doesn't returns back to code in TurboC++. However, it works fine for words with 1 and 3 characters. It also runs perfectly in CodeBlocks.
#include<conio.h>
#include<stdio.h>
#include<iostream.h>
#include<string.h>
void main()
{
clrscr();
char * name;
cout<<"Enter your name : ";
gets(name);
int len = strlen(name);
for(int i=0;i<len;i++)
{
cout<<name[i]<<" "<<i<<endl;
}
getch();
}
If I change char* to char name[20], it works perfectly. Can anyone please explain the reason for it. If their is problem in char *, then why does CodeBlocks runs it without any problem?