Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Language%20in%20C%20Interview%20Questions%20and%20Answers

Question: What would the second and the third printf( ) output the following program?

main( )
{
char *str[ ] = {
"Good Morning"
"Good Evening"
"Good Afternoon"
} ;
printf ( "nFirst string = %s", str[0] ) ;
printf ( "nSecond string = %s", str[1] ) ;
printf ( "nThird string = %s", str[2] ) ;
}
Answer: For the above given program, we expect the output as Good Evening and Good Afternoon, for the second and third printf( ). However, the output would be as shown below.

First string = Good MorningGood EveningGood Afternoon
Second string = ( null )
Third string =

What is missing in the above given code snippet is a comma separator which should separate the strings Good Morning, Good Evening and Good Afternoon. On adding comma, we would get the output as shown below.

First string = Good Morning
Second string = Good Evening
Third string = Good Afternoon
Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook