M
0
Whitespace is a term that refers to characters that are used for formatting purposes. In C++, this refers primarily to spaces, tabs, and (sometimes) newlines. The C++ compiler generally ignores whitespace, with a few minor exceptions.
Consequently, the following statements all do the exact same thing:
1
2
3
4
5
6
7
8
cout << "Hello world!";
cout << "Hello world!";
cout << "Hello world!";
cout
<< "Hello world!";
Even the last statement with the newline in it compiles just fine.
The following functions all do the same thing:
1
2
3
4
5
6
7
8
9
10
11
12
int add(int x, int y) { return x + y; }
int add(int x, int y) {
return x + y; }
int add(int x, int y)
{ return x + y; }
int add(int x, int y)
{
return x + y;
}
One exception where the C++ compiler does pays attention to whitespace is inside quoted text, such as "Hello world!".
"Hello world!"
is different than
"Hello world!"
and each prints out exactly as you
Consequently, the following statements all do the exact same thing:
1
2
3
4
5
6
7
8
cout << "Hello world!";
cout << "Hello world!";
cout << "Hello world!";
cout
<< "Hello world!";
Even the last statement with the newline in it compiles just fine.
The following functions all do the same thing:
1
2
3
4
5
6
7
8
9
10
11
12
int add(int x, int y) { return x + y; }
int add(int x, int y) {
return x + y; }
int add(int x, int y)
{ return x + y; }
int add(int x, int y)
{
return x + y;
}
One exception where the C++ compiler does pays attention to whitespace is inside quoted text, such as "Hello world!".
"Hello world!"
is different than
"Hello world!"
and each prints out exactly as you