Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

What would be the result of the c program ?

What would be the result of this program in c++. #include<iostream.h> - imports the file iostream.h Void main (void) { Cout<<”Hello World\\n”; } What would be the difference in output Cout<<”Hello World\\n Hello beautiful world \\n”; What happens when \\n is deleted. Cout<<”Hello world “; look for the difference in the position of the cursor

user-image
Question ajoutée par Subhranshu Ganguly , Quality Analyst. , WIPRO
Date de publication: 2013/12/26
Daniel Marx
par Daniel Marx , Software Developer , Check24

The '\\’ in general is, as Fedy Thankachan already mentioned an escape sequence, giving the compiler the information about a non-printable sequence, like "new line (\\n)".

The crux with this concept is "How to print the actual '\\' then? The solution is to escape the escape sequence by prefixing it with another '\\'.

Getting back to your example:

Cout<<”Hello World\\\\n Hello beautiful world \\\\n” => Hello World\\n Hello beautiful world\\n"

Cout<<"Hello World\\\\\\\\n Hello beautiful world\\\\\\\\n => Hello World\\\\n Hello beautiful world\\\\n

and removing both \\\\n:

Cout <<"Hello World Hello beautifu word" => Hello World Hello beautiful world

 

In all three examples the \\n (new lines) have been escaped or removed, so there shouldn't be any new lines in the output left.

 

 

 

Emad Mohammed said abdalla
par Emad Mohammed said abdalla , ERP & IT Software, operation general manager . , AL DOHA Company

I agree with the answer added by:

Daniel Marx   Daniel Marx

Daniel Marx Developer at Eastline Marketing

Follow

 

 

Utilisateur supprimé
par Utilisateur supprimé

It should be "\\n" not "\\\\n"...\\n is an escape sequence to make a new line..

So if you put Cout<<”Hello World \\n Hello beautiful world \\n”;you may get an output like this

Hello World

Hello beautiful world

Yogesh Dhakad
par Yogesh Dhakad , Director Technical , Timeless Horizon Engineering Solutions

No newline (carriage return + line feed) will be printed of the standard output device.

 

You need to revise a little about using "escape sequences" in C (same in C++).

Utilisateur supprimé
par Utilisateur supprimé

what you have to know ''\\\\n'' Goto new line 

its the same in pascal

Write and Writeln

read and readln

Utilisateur supprimé
par Utilisateur supprimé

Hello World\\n Hello beautiful world

Khalid Omar
par Khalid Omar , Senior .NET Developer / Associate Technology Manager , Musafir.com (Universal Tourism)

1) First fo all, it is \\n not \\\\n

2) Second, you should use cout instead of Cout (C/C++ is case sensitive)

3) You should use void main(void) instead of Void Main(void)

4) \\n prints a new line to the output. Meaning that, the cursor moves to the begining of the following line. Anything printed will apper on the next line

More Questions Like This