Question 9519 – C-Programming
November 11, 2023Pointers
November 11, 2023Question 9521 – C-Programming
Consider the following C program segment:
char p[20]; char *s = "string"; int length = strlen(s); int i; for (i = 0; i < length; i++) p[i] = s[length — i]; printf("%s",p);
The output of the program is
Correct Answer: D
Question 9 Explanation:
Every string is to be end with ‘\0’.
P[0] = S[7-1] = S[6] = \0.
In P[ ], the first character is ‘\0’. Then it will results a empty string. If P[0] become ‘\0’, then it doesn’t consider about next values in sequence.
P[0] = S[7-1] = S[6] = \0.
In P[ ], the first character is ‘\0’. Then it will results a empty string. If P[0] become ‘\0’, then it doesn’t consider about next values in sequence.
gnirts
string
gnirt
no output is printed
Subscribe
Login
0 Comments