Printing of string with %s format specifier yields no output
So I came across a question in a C challenge, and I just want to make sure I understand why the answer is the way it is. The question is asking for the output of the following code: char p[20]; char *s = "string"; int length = strlen(s); for (int i = 0; i < length; i++) p[i] = s[length - i]; printf("%s", p); The correct answer is No output. At first I thought it was because '\0' was assigned to the first character, so maybe the characters after it weren't read when printing. I know C strings cannot be reassigned as a whole, but their elements can, similar to arrays of other data types. I know this because I could reassign and print out the other characters of the string individually. I changed the initialization of i in the for loop to 1, the condition to i <= length, and even added a '\0' after the last character in the array, but it still does not output anything when I use the %s format specifier. What's going on?