C Programming - Control Instructions - Discussion

2. 

If scanf() is used to store a value in a char variable then along with the value a carriage return(\r) also gets stored it.

[A]. True
[B]. False

Answer: Option B

Explanation:

No, the carriage return tells the compiler to read the input from the buffer after ENTER key is pressed.


Ajay said: (May 17, 2012)  
What is carriage return?can someone please explain.

Muskaan said: (Dec 13, 2012)  
Carriage return is '\r'.

It puts the cursor to the beginning of the line *while run time*.

Divya said: (Jan 29, 2015)  
Ex:

printf("abc");
printf("\rde");

Then output is: dec.

Suraj said: (Oct 12, 2015)  
If it puts the cursor at the beginning of line then how output comes "dec"?

Suraj said: (Oct 12, 2015)  
Where is ab?

Rishabh said: (Mar 24, 2016)  
First printf statement executes the abc when the second printf execute the first carriage return will place the cursor at the beginning of line then abc will be overridden with dec.

Rishi said: (Mar 24, 2016)  
abc is override by the dec because \r return the cursor to beginning of the line.

Shital said: (Aug 8, 2016)  
Thanks. I totally understand about carriage return.

Srikanth said: (Dec 28, 2017)  
Anyone give any example program for the above question?

Prashant Bhosale said: (Jul 19, 2020)  
What is the meaning of /r?

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.