Vidyalelo
C Programming · Q61

Arrays and Strings

Programming · C Programming · question 61

Q61

What will be the correct output of the following program? #include void main() char str[] = "C EXAMINATION", rev[17]; int i = strlen(str), j=0; for( ; i>=0; rev[j++] = str[i--]) rev[j] = str[j] ; puts(rev);

A.
NOITANIMAXE C
B.
NOITANIMAXE
C.
C
D.
No output at all.
Answer
E.
Syntax error

Answer: Option D

Solution

Answer: Option D
Solution:

As i is with the length of string and hence in array rev the contents are copied as "\0 NOITANIMAXE C". But while displaying those contents with puts function it stops because of the first character '\0' and hence no output.