they say space doesn't matter but after cout I written like this "this is awesome" so why that long space appears in output why ? | Sololearn: Learn to code for FREE!
0

they say space doesn't matter but after cout I written like this "this is awesome" so why that long space appears in output why ?

12th Apr 2017, 2:26 AM
savethetime
5 Answers
+ 5
space does matter when printing strings
12th Apr 2017, 2:28 AM
Edward
+ 5
Statements in C/C++ can be written with or without whitespace, compiler never mind, even if you write entire code in a single line. We add whitespace to increase readability. So it really doesn't matter to compiler if your write like int main (void) { cout<<"Hello World"; } OR int main (void){ cout << "Hello World"; } OR int main (void){ cout<<"Hello World"; } But when it comes to string literal each space in it counts. Hence the string values are handle in same way, the way they were entered. "this is awesome" is different from "this is awesome" as both have varying number of characters including spaces.
12th Apr 2017, 4:30 AM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
+ 1
the compiler ignores spaces in your code. it woyld be drammatic if it ignored also spaces within strings ifthecompilerignoredspacesinastring,outputwouldlooklikethis.doyoufinditusefulornot?
12th Apr 2017, 5:30 AM
seamiki
seamiki - avatar
+ 1
Space doesnt count for the line or white space u left in between code lines. But when it comes to printing strings, then space matters. :)
12th Apr 2017, 1:43 PM
Tanmay Maiti
Tanmay Maiti - avatar
0
space matter in strings only at this level .hope this help.
12th Apr 2017, 10:32 AM
code