C Programming - Strings - Discussion

Discussion Forum : Strings - General Questions (Q.No. 3)
3.
How will you print \n on the screen?
printf("\n");
echo "\\n";
printf('\n');
printf("\\n");
Answer: Option
Explanation:

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

Discussion:
23 comments Page 1 of 3.

Raj said:   1 decade ago
\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

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

Srilakshmi said:   1 decade ago
By using printf("\n"); we get blankscreen as \n is a white space character but printf("\\n"); gives output as \n

Priya said:   7 years ago
@Komal.

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

Vinod said:   1 decade ago
This is verbatim string. Putting any special character after "\" sign ignoresthe next character for compilation.

Jayasai said:   8 years ago
If we put "ffn" in printf it showing output as ffn. But in question, they asked to print "fn".

Ugn said:   1 decade ago
The question is quite ambiguous - not clear whether a string or the character \n is wanted t print.

Praveen Negalurmath said:   5 years ago
If u put printf("\\n");

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

Vavilapalli sateesh said:   8 years ago
"\\n "means it gives the output to the user whereas in "\n"gives white space and leave some lines.
(1)

Shashank said:   1 decade ago
Give me specific reason about this answer. Why there is "\\" is used ?


Post your comments here:

Your comments will be displayed after verification.