Writing C++
C++ is a very flexible language when it comes to formatting and writing code. It is also a strongly typed language, meaning there are rules about declaring the types of variables, which you can use to your advantage by making the compiler help you write better code. In this section, we will cover how to format C++ code and rules on declaring and scoping variables.
Using white space
Other than string literals, you have free usage of white space (spaces, tabs, newlines), and are able to use as much or as little as you like. C++ statements are delimited by semicolons, so in the following code there are three statements, which will compile and run:
int i = 4; i = i / 2; std::cout << "The result is" << i << std::endl;
The entire code could be written as follows:
int i=4;i=i/2; std::cout<<"The result is "<<i<<std::endl;
There are some cases where white space is needed (for example, when declaring a variable you must have white space between...