The Basic Program Structure
Listing 2.1 shows the source code for your first C++ program. It welcomes you to the world of C++ (as most first programs in programming language books do). In addition, just to demonstrate more features than a canonical "Hello World" program does, it makes some simple computations and prints the result of raising the value of pi (3.1415926) to the power of two.
Code Listing 2.1. Your first C++ program.
#include <iostream> // preprocessor directive #include <cmath> // preprocessor directive using namespace std; // compiler directive const double PI = 3.1415926; // definition of a constant int main(void) // function returns integer { double x=PI, y=1, z; // definitions of variables cout << "Welcome to the C++ world!" ... |
Get Core C++ A Software Engineering Approach now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.