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.

Sunny said:   1 decade ago
Great. Really good one example.

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

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

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

Karthik saakre said:   1 decade ago
Actually, printf ("\n") : will skip a line leaving the current line.

Tina Jadhav said:   1 decade ago
Usually we use \n, never heard about"\\n". When we have to use this?

Sasi said:   1 decade ago
Never heard about "\\n" can anyone explain in detail?

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

Suraj kumar said:   1 decade ago
Can anyone explain, how the statement. echo "\\n";. Works ?

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


Post your comments here:

Your comments will be displayed after verification.