| s | t | r | i | n | g | \0 |
| s[0] | s[1] | s[2] | s[3] | s[4] | s[5] | s[6] |
note: string literals always ends with a null character (\0)
s is a pointer to string literal and it is pointing to the first element of "string" (ie s)
length of the string is 6 so strlen(s) will return 6 and int length will be 6
since length is 6 the for loop will run from 0 to 5
for(i = 0; i < length; i++)
p[i] = s[length-i];this will become
for(i = 0; i < 6; i++)
p[i] = s[6-i];
for i=0 --> p[0] = s[6-0] =s[6] --> s[6] is a null character (\0) so we will add it in our char array p at p[0]
for i=1 --> p[1] = s[6-1] =s[5] --> s[5] is g and we will add it at p[1]
for i=2 --> p[2] = s[6-2] =s[4] --> s[4]=n
for i=3 --> p[3] = s[6-3] =s[3] --> s[3]=i
for i=4 --> p[4] = s[6-4] =s[2] --> s[2]=r
for i=5 --> p[5] = s[6-5] =s[1] --> s[1]=t
for i=6 --> the condition i<6 fails
so the array p will look like
| \0 | g | n | i | r | t |
| p[0] | p[1] | p[2] | p[3] | p[4] | p[5] |
printf("%s", p); here the %s is used to print a string and it prints from the first element of the string untill it finds the null character
Here the first element is null (\0) itself so it will print nothing. Hence the correct ans
D. no output is printed