ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

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
تم إضافة السؤال من قبل Subhranshu Ganguly , Quality Analyst. , WIPRO
تاريخ النشر: 2013/12/26
Daniel Marx
من قبل 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
من قبل 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

 

 

مستخدم محذوف‎
من قبل مستخدم محذوف‎

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
من قبل 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++).

مستخدم محذوف‎
من قبل مستخدم محذوف‎

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

its the same in pascal

Write and Writeln

read and readln

مستخدم محذوف‎
من قبل مستخدم محذوف‎

Hello World\\n Hello beautiful world

Khalid Omar
من قبل 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

المزيد من الأسئلة المماثلة