Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the output of this C code?

int main()
{
printf("AllIndiaExams\r\nclass\n");
return 0;
}

 

  • A.AllIndiaExamsclass
  • B.AllIndiaExams class
  • C.classundry
  • D.AllIndiaExams

Answer: B

Correct answer: AllIndiaExams class

The string contains \r\n between the two words. The carriage return returns the cursor to the start of the line and the newline moves it down one, so on a terminal the effect is simply to end the line - AllIndiaExams appears on one line and class on the next.

The carriage return alone would have returned to the start of the same line, so subsequent text would overwrite what was already there. Combined with the newline, its effect is invisible, which is why the two characters together are the conventional line ending on some systems.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.