Given a string , say ,
char *str = \"Hello,StackOverflow!\"
char newStr[30];
int l = strlen(str);
for(int i =0 ; i
Your program has undefined behaviour, since you promise to call printf
with a pointer to a null-terminated string but fail to do so. Anything could happen, but your program is simply not correct.
Specifically, while reading the array elements one by one to find the null terminator, the program will eventually access an uninitialized variable, which is UB.