Screen output // Definition and use of variables #include <iostream> using namespace std; int gVar1; // Global variables, int gVar2 = 2; // explicit initialization int main() { char ch('A'); // Local variable being initialized // or: char ch = 'A'; cout << "Value of gVar1: " << gVar1 << endl; cout << "Value of gVar2: " << gVar2 << endl; cout << "Character in ch: " << ch << endl; int sum, number = 3; // Local variables with // and without initialization sum = number + 5; cout << "Value of sum: " << sum << endl; return 0; } Screen output Value of gVar1: 0 Value of gVar2: 2 Character in ch: A Value of sum: 8
// Circumference and area of a circle with radius 2.5 #include <iostream> using namespace std; const double pi = 3.141593; int main() { double area, circuit, radius = 1.5; area = pi * radius * radius; circuit = 2 * pi * radius; cout << "\nTo Evaluate a Circle\n" << endl; cout << "Radius: " << radius << endl << "Circumference: " << circuit << endl << "Area: " << area << endl; return 0; } Screen output To Evaluate a Circle Radius: 1.5 Circumference: 9.42478 Area: 7.06858
The C++ Compilation Model & IDE
Everything is Done Using an IDE Using Integrated Editor Everything is Done Using an IDE
Fill-in-the-Blank Questions 1. Compilers detect ________ errors. 2. Usually the most difficult errors to correct are the ________ errors, since they are not detected in the compilation process. 3. Attaching other pre-written routines to your program is done by the _________ process. 4. _______code is the machine code consisting of ones and zeroes that is read by the computer. 5. Dividing by zero is an example of a _________ error.