محاضرة 3
Operators (Increment/Decrement, Precedence, Logical)
معاملات الزيادة والنقصان، الأسبقية، والمعاملات المنطقية
ملخص المحاضرة
📜 Lecture 3: Operators (Increment, Logical, Priority)
This lecture details operator precedence, increment/decrement operators, and logical operators for comparisons.
Key Concepts
- Increment/Decrement Operators:
- Postfix (e.g.,
Z++orZ--): "Use-then-change". The variable's original value is used in the expression, and then it is incremented/decremented by 1. - Prefix (e.g.,
++Zor--Z): "Change-then-use". The variable is incremented/decremented by 1 first, and then its new value is used in the expression. - Example (Postfix):
int Z=5; X = Z++;->Xbecomes5, thenZbecomes6. - Example (Prefix):
int Z=5; X = ++Z;->Zbecomes6, thenXbecomes6.
- Postfix (e.g.,
- Arithmetic Priorities: The order in which C++ performs operations.
()(Brackets)++,--(Increment/Decrement)*,/,%(Multiplication, Division, Modulus)+,-(Addition, Subtraction)=(Equality/Assignment)
- Logical (Comparison) Operators: Used to compare values, resulting in
true(1) orfalse(0).>(Greater than),<(Less than),>=(Greater or equal),<=(Less or equal),==(Equal to),!=(Not equal).
- Logical (Boolean) Operators: Used to combine multiple conditions.
&&(AND): Returnstrue(1) only if all conditions aretrue.(10 > 6 && 10 > 7)istrue(1).(10 > 6 && 10 > 11)isfalse(0).
||(OR): Returnstrue(1) if at least one condition istrue.(10 > 6 || 10 > 11)istrue(1).
!(NOT): Reverses the result.
محتويات المحاضرة
اختبر فهمك للمحاضرة
تصحيح فوري بالذكاء الاصطناعي