|
|
Basics |
|
Rules for identifiers are the same as the C rules.
Loops are exactly the same as in C. This includes for,
do, and while loops.
if and switch are done exactly the same
as in C.
Variables are declared the same way except they no longer need to be declared at the top of the scope. They can be declared anywhere and the only condition is that they must be declared before they are used.
In the following program notice the location of the variable declarations.
#include <iostream>
using namespace std;
int main (int argc, char** argv) {
int i = 5;
i += 2;
int j = i + 10;
j = j + i;
double k = 5.0 * j;
k *= i;
return 0;
}