Discussion
What is the output of this C code?
#include <stdio.h>
int main()
{
printf("sanfoundry\r\nclass\n");
return 0;
}
Answer: B
Correct answer: sanfoundry class
Here the carriage return is followed by a newline. The carriage return moves the cursor to the start of the line and the newline moves it down one, so nothing is overwritten and the two words appear on separate lines.
Compare this with the same code using \r alone, which prints classundry because the second word overwrites the first. The pair \r\n is the conventional line ending on some systems, and its combined effect is simply to end the line.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development