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 ?
5 Réponses
+ 5
space does matter when printing strings
+ 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.
+ 1
the compiler ignores spaces in your code.
it woyld be drammatic if it ignored also spaces within strings
ifthecompilerignoredspacesinastring,outputwouldlooklikethis.doyoufinditusefulornot?
+ 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. :)
0
space matter in strings only at this level .hope this help.