Lesson 2: Statements, Expressions and Operators
During this lesson, we remind ourselves of the definition of a C++ statement, before introducing the new concept of an expression. The greater part of the lesson is then used discussing arithmetic operators.
Sourcecode
The following source code is used during this video.
#include <iostream>
int main()
{
// this is a statement:
std::cout << "This output is the result of a statement." << std::endl;
// each of these sums is an expression
std::cout << 4 + 5 << ' ' << 7 - 1 << ' ' << 3.14 * 7.0 << ' ' << 4.0 / 7.3 << std::endl;
// they can be more complex
std::cout << 4 - (5 * 6) / 2 << std::endl;
// take care mixing integers and decimal numbers, and dividing integers
std::cout << 5 / 3 << ' ' << 4.0 * 5 << std::endl;
// introducing the modulus operator (integers only!)
std::cout << 4 % 3 << ' ' << 41 % 8 << std::endl;
return 0;
}
Exercises
Comments (0)
Trackbacks (0)
Leave a comment
Trackback
