Breaking instructions into multiple lines
If you're asking about writing code, then code can be broken in any arbitrary number of lines where a token ends.
Look at the following loop:
int sum = 0;
for (int i = 0; i < 10; i++)
{
sum += i;
}
This could be written as a single line:
int sum = 0; for (int i = 0; i < 10; i++) sum += i;
Or you can break it into multiple lines where a token ends (so do not break in the middle of a word). E.g.:
int sum = 0;
for
(
int i = 0;
i < 10;
i++
)
{
sum
+=
10
;
}
These are all equivalent and generate the same machine code.
Breaking strings into multiple lines
If you want to break strings into multiple lines, all you need to do is close the string before the end of the line with a quote and continue in the next line within a new pair of quotes:
std::string cppString = "This string"
"really is only"
"one line";
char * cString = "This is"
"also just"
"one line, when printed".
As you can see, the compiler ignores any while space when you break strings up into multiple lines in the code (yet they remain a single line for the compiler).
The backslash
With the use of backslash (\), you tell the compiler that you want to continue the line where you are. You can place it anywhere (even within words). The compiler will glue the next line to the end of this one. For this, white spaces are not to be ignored.
So this one works just fine:
std::string myString = "This is\
also a single line";
int sum = 3;
su\
m +\
= 15; // sum += 15. You can place the backslash within identifiers (sum) or withing operators (+=) too.
However, due to the backslash (\) taking white space into account, the following do not work:
int sum = 3;
sum +\
= 15; // The compiler does not understand what sum + = 15 is. We wanted sum += 15, but what we wrote above was + operation followed by = operation.