Given a string , say ,
char *str = \"Hello,StackOverflow!\"
char newStr[30];
int l = strlen(str);
for(int i =0 ; i
A "crash" is not guaranteed. A program that improperly handles null terminators in strings - more generally accesses data outside of buffer boundaries - or violates the printf
format string, may seem to work just fine, functioning and not e.g. causing a segfault. But this is just happenstance: the behavior of your code is undefined.
It will be the same in C++.