C Programming - Strings - Discussion

3. 

How will you print \n on the screen?

[A]. printf("\n");
[B]. echo "\\n";
[C]. printf('\n');
[D]. printf("\\n");

Answer: Option D

Explanation:

The statement printf("\\n"); prints '\n' on the screen.


Sunny said: (Mar 17, 2011)  
Great. Really good one example.

Shashank said: (Sep 18, 2011)  
Give me specific reason about this answer. Why there is "\\" is used ?

Vinod said: (Jan 7, 2012)  
This is verbatim string. Putting any special character after "\" sign ignoresthe next character for compilation.

Srilakshmi said: (Jul 7, 2012)  
By using printf("\n"); we get blankscreen as \n is a white space character but printf("\\n"); gives output as \n

Karthik Saakre said: (Apr 14, 2013)  
Actually, printf ("\n") : will skip a line leaving the current line.

Tina Jadhav said: (Aug 22, 2013)  
Usually we use \n, never heard about"\\n". When we have to use this?

Sasi said: (Sep 19, 2013)  
Never heard about "\\n" can anyone explain in detail?

Raj said: (Oct 16, 2013)  
\n -> takes the control to the newline if we give printf("\n").

So if we add one more \ it loses the newline property.

printf("\\n") -> it will print \n

printf("\\b") -> it prints \b

Suraj Kumar said: (Jul 27, 2014)  
Can anyone explain, how the statement. echo "\\n";. Works ?

Ugn said: (Jan 18, 2015)  
The question is quite ambiguous - not clear whether a string or the character \n is wanted t print.

Apshana said: (Jul 15, 2015)  
Why \ is used before \n?

Datta said: (Jan 23, 2016)  
Please explain me that?

Venkatesh said: (Jul 6, 2016)  
\ is escape sequence escape after letter while compilation.

Anuja said: (Jul 9, 2016)  
\n changes the line. But we wanna print \n so we have to take one "\".

Pradeepa said: (Jul 27, 2016)  
This was really a good concept & useful discussion, Thank you friends.

123 said: (Sep 6, 2016)  
Please explain the concept with an example.

Vavilapalli Sateesh said: (Mar 6, 2017)  
"\\n "means it gives the output to the user whereas in "\n"gives white space and leave some lines.

Jayasai said: (Jun 13, 2017)  
If we put "ffn" in printf it showing output as ffn. But in question, they asked to print "fn".

Saroj Kumari said: (Sep 15, 2017)  
Really, good concept.

Sangami said: (Jul 25, 2018)  
'\n' is the backslash character constant. specifically, it is an escape sequence. Thus to print backslash character itself put backslash (\) before that character.

Komal More said: (Aug 6, 2018)  
Why there is "\\" used?

Priya said: (Sep 9, 2018)  
@Komal.

\\n is used for print\n
print("\\n")->it print \n
print("\\s")->it print \s
likewise it print.

Praveen Negalurmath said: (Jun 12, 2020)  
If u put printf("\\n");

It could have printed \, why does it prints \n? Anyone explain.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.