Following is code snippet :
char *b = NULL;
b = new char[5];
if(b != NULL) {
printf("b=%p\n",b);
sprintf(b, "helloPLS...123456789123456789");
printf("b = %s\n", b);
}
output : b = helloPLS...123456789123456789
If only 5 bytes were allocated then why all "helloPLS...123456789123456789" string is added into 5 byte memory?
My program works perfectly fine.