3.2-Applying Unary Operators Flashcards

1
Q

What is a unary operator?

A

A unary operator is one that requires exactly one operand

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the Unary Operators and its precedece?

A
  • > Post-Increment/Decrement operators ++ –
  • > Pre -Increment/Decrement operators ++ –
  • > Unary plus operator +
  • > Unary minus operator -
  • > Bitwise complement operator ~
  • > Logical complement operator !
  • > Casting operator (type)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the Increment/Decrement operators, ++ and – do?

A

Respectively, can be applied to numeric operands and have a high order of precedence, as compared to binary operators.

🚀️ If the operator is placed 💥️BEFORE💥️ the operand, referred to as the pre-prefix operator.
🚀️ If the operator is placed 💥️AFTER💥️ the operand, referred to as the post-prefix operator.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

🤯️⚠️📣️ What is the Post-prefix operator PITFALL case?

A

If the operand the post-prefix is being applied to is used in both sides of an assignment-expression.
-> The variable might NOT get incremented/decremented.
e.g: int x = 10, y = 10;
🕵‍♂️️ x = x++ + y; //20 ❌
🕵‍♂️️ x = x++ + y + x++; //31 ✅

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the negation/minus operator, ‘-‘ do?

A

Reverses the sign of a numeric expression.

🚀️ By default every numeric expression goes with a plus operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the logical complement operator (!) do?

A

Flips the value of a boolean expression.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the Unary bitwise complement symbol, what operation it performs?

A

bitwise complement ~ -> -(N +1) e.g: ~5 => -6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly