-
Consider the following C program segment :
char p [20]
char *s = “string”;
int length = strlen (s);
for (i = 0; i < length, i++)
p[i] = s [length – i];
print f(“%s”, p);
The output of the program is
-
- gnirts
- garbage dashing or no value printed
- gnirt
- no output is printed
- gnirts
Correct Option: D
Let us consider below line inside the for loop.
P[i] = S[length – i];
For i = 0, P[i] will be S[6 – 0) and S [6] is ‘10’.
So, P[0] becomes ‘10’. It does not matter what comes in P[1], P[2] ........ as P[0] will not change for i > 0.
Nothing is Printed if we print a string with first character ‘10’.