Structure of a Program 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 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 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> Function body

Enclosed by curly braces


} Console output

Send text to cout (console output)

cout << "text to send to console"; Return

Returns the value 0 to the operating system - everything went ok

return 0; 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