GATE | Gate IT 2008 | Question 47

What is the output printed by the following C code?

filter_none

edit
close

play_arrow

link
brightness_4
code

# include <stdio.h>
int main ()
{
    char a [6] = "world";
    int i, j;
    for (i = 0, j = 5; i < j; a [i++] = a [j--]);
    printf ("%s\n", a);
}
 /* Add code here. Remove these lines if not writing code */ 

chevron_right


(A) dlrow
(B) Null String
(C) dlrld
(D) worow


Answer: (B)

Explanation: As at the base address or starting of the string “Null” is placed, so while reading array if Null comes it assumes that this is the end of array, so it terminates here only.

Quiz of this Question



My Personal Notes arrow_drop_up


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.