2.1.1.2. Structure of a Program¶
2.1.1.2.1. Statements - perform an action¶
“The unit of meaning isn’t the word”
Statements are the smallest independent unit in C++
Most statements end with a semicolon
Types of statement:
Declaration statements
Jump statements
Expression statements
Compound statements
Selection statements (conditionals)
Iteration statements (loops)
Try blocks
2.1.1.2.2. Functions - collection of statements executing sequentially¶
Functions are groups of statements
Every C++ program must have a main() function
The first statement in the main() function runs first
Parentheses added to the function to distinguish it from variables
2.1.1.2.3. Pre-processor directive¶
Use contents of iostream library for cout
iostream is part of the C++ standard library
The C++ standard library is packaged upcode that can be used for added fuctionality
#include <iostream>
2.1.1.2.7. Syntax¶
C++ grammatical rules governing how programs are structured to be considered valid
Errors are reported like this:
test.cpp: lineNumber : columnNumber
In VIM this corresponds to lineNumber, columnNumber shown in bottom right
Errors can actually be on the previous line, as they may only be discovered on subsequent lines