> Dude I am using Dev C++ 4.9 compiler and It does not even without the increments.
/facepalm you just said you tested with turbo c.
Anyway, make these changes:
Code:
#include <iostream>
/* no more conio */
using namespace std;
int main()
{
char *name;
int size;
cout<<"Enter size";
cin>>size;
name=new char[size+1]; /* no more buffer overflow */
getchar(); /* get rid of the newline character */
fgets(name,size,stdin);
cout<<"Name is "<<name;
delete [] name; /* don't ever forget to free memory */
return 0;
}