Procedural: Variables, types, scopesTrail Index | Procedural | Variables /** * variables, calculations, types, scopes */ // include standard input/output streams for C++ #include <iostream> /** * main function */ int main() { // with "using" you don't need to always specify std:: using std::cout; using std::endl; // note: multiple statements on one line cout<<"Example 1\n"; // \n is another way to say new-line, inside a literal text const int a=2; // a constant - int for "integer" const int b=3; cout<< a+b <<endl; // calculation cout<< b/a <<endl; // unexpected(?) result - types { // a separate scope cout<<"Example 2\n"; const int a=2; const double b=3; // double for "double precision floating point" cout<< a+b <<endl; cout<< b/a <<endl; // better result; a is "upgraded" to double } { cout<<"Example 3\n"; int a=2; // not const anymore, really a "variable" const int b=3; a=a+b; // assignment cout<< a <<","<< b <<endl; //a more complex cout } return 0; // zero means all is well } |