Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

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 added by Subhranshu Ganguly , Quality Analyst. , WIPRO
Date Posted: 2013/12/26
Daniel Marx
by 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
by 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

 

 

Deleted user
by Deleted user

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
by 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++).

Deleted user
by Deleted user

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

its the same in pascal

Write and Writeln

read and readln

Deleted user
by Deleted user

Hello World\\n Hello beautiful world

Khalid Omar
by 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