CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

What is the output printed by the following C 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);
}

A
worow
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
dlrow
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
Null string
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
D
dlrld
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is C Null string
char a[6] =
w o r l d \0
a[0] 1 2 3 4 5

When Loop will execute first time,
a[0] = a[5]
a[0] = '\0'
printf ("%s", a), the string starting at address a prints the string starting with '/0' and it indicates the end of string, so it will print null string.

flag
Suggest Corrections
thumbs-up
2
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Fear of the Dark
QUANTITATIVE APTITUDE
Watch in App
Join BYJU'S Learning Program
CrossIcon