C++ Object-Oriented Flashcards
(108 cards)
Expression
An entity with a value that can possibly change that state of memory
Plus
+expr
Minus
-expr
size of
sizeof (expr)
multiplication
expr * expr
Division
expr / expr
remainder
expr % expr
addition
expr + expr
subtraction
expr - expr
simple assignment
variable = expr
comp. assignment
variable op=expr
Literals
Constant values, such as numbers or strings
int num = 10; // 10 is a literal
Variables
Named memory locations whose values can change during program execution
int x = 5;
Operators
Symbols that represent operations to be performed on operands
Arithmetic operators
*
/
Assignment operator
=
Relational operators
==
!=
<
>
<=
>=
Logical operators
&&
||
!
Parentheses
Used to group expressions and alter the order of operations. Can be used to explicitly define the order of evaluation.
int result = (x + y) * 2;
Function calls
Can be part of expressions if they return values
int sum = add(x, y);
Type conversion
When a value is changed from one data type to another in an expression. C++ may perform type conversion when operands of different types are used together in an expression.
int result = 5 + 3.5; // 5 is implicitly converted to a floating-point number
Expression evaluation
Based on the precedence and associativity of operators.
1. Parentheses
2. Unary operators
3. Multiplicative
4. Additive
5. Relational/equality
6. Logical
7. Assignment
Expression evaluation
Based on the precedence and associativity of operators.
1. Parentheses
2. Unary operators
3. Multiplicative
4. Additive
5. Relational/equality
6. Logical
7. Assignment
Primary expression
Basic unit of expressions. Can represent a value or operation in an expression.
Example:
Literal
“Hello” // string literal