أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
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
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.
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
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
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