Operators And Its Precedence Flashcards

1
Q

Operator’s precedence

A

The order in which the operators are evaluated in a compound expression

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

Precedence

A

All operators in C++ are assigned a level of precedence, operators with higher level are evaluated first

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

Operator associativity

A

It tells the compiler the direction of evaluation of operators that are assigned the same level of precedence

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

Precedence levels

A

1 is highest, 17 is lowest

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

Parenthesis

A

Used to make it clear how the expression should be evaluated, even if they are unneccesary

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

Unary arithmetic operators

A

Plus and minus, should be placed immediately preceding the operand

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

Unary minus

A

Returns the operand multiplied by -1

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

Unary plus

A

Returns the value of the operand

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

Binary arithmetic operators

A

Addition, subtraction, multiplication, division and modulus (remainder%)

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

Floating point division

A

Occurs when either of the operands are floating poating point values, returns a floating point value and the fraction is kept

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

Integer division

A

If both of the operands are integers it drops fractions and returns an integer value.

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

Using static_cast<> to do floating point division with integers

A

Use static_cast<> to convert an integer to floating point number

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

Dividing by zero

A

Will generaly cause the program to crash

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

Arithmetic assignment operators

A

Assignment, additional assignment, subtraction assignment, multiplication assignment, division assignment and modulus assignment

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

Modulus operator

A

Operator that returns the ramainder after doing an integer division, only works with integer operands

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

Use for modulus

A

For testing whether a number is evenly divisable by another number

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

Modulus with negative numbers

A

Returns result with the sign of x (x/y)

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

Exponent operator (^)

A

Bitwise XOR operator

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

Exponent in C++

A

C++ doesn’t include exponent operator, exponents are done with #include the header and using the pow() function

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

Parameters and return value of pow()

A

Type double, due to rounding errors in floating point numbers, the result may not be precise.

21
Q

Incrementing and decrementing

A

Adding 1 to and subtracting 1 from

22
Q

Prefix increment/decrement

A

If we use it the operand is incremented/decremented and the expression evaluates to the value of the operand

23
Q

Postfix increment/decrement

A

A copy of the opedand is made, yhe operand is incremented/decremented and the copy is evaluated

24
Q

Side effects

A

If a function or expression does anithing that persists beyond the life of the function/ expression itself

25
Q

Common side effects

A

Changing the value of objects, doing input or output or updating a graphical user interface

26
Q

Comma operator

A

Allows to evaluate multiple expressions when a single expression is allowed, evaluates the left then the right operand and returns the result of the right

27
Q

Other use of comma

A

As a seperator, it doesn’t invoke the comma operator

28
Q

Conditional operator ?:

A

Ternary operator, provides a shorthand method for doing particular type of if/else statement

29
Q

Paranthesization of the conditional operator

A

Conditional operator has low precidence, so it is common convention to paranthesize at least the conditional part of the operator

30
Q

Evaluation of the conditional operator

A

As an expression, must match the type of both expressions or the second expression must be convertable to the type of the first

31
Q

Use of conditional operator

A
  • ehen we need a conditional initializer or assignment for a variable
  • to pass conditional value to a function
  • simple conditionals
  • do Not use for complex if/else statements
32
Q

Relational operators

A

Operators that let you compare two values, it evaluates to a boolean value

33
Q

Comparison and equality with floating point

A

Comparison can be done but it can’t be too precise, equality should be avoided.

34
Q

Floating point equality

A

Can be done by using a function that looks to see if two numbers are almost the same

35
Q

Epsilon

A

Small positive number, value that represents “close enough”

36
Q

std::abs()

A

Function in the header that returns the absolute value of its argument *downside-everytime we call the function we have to pick an epsilon appropriate to the input

37
Q

Donald knut method

A

Epsilon is relative to a or b, it is calculated by algorithams choice of the larger a or b and multiplies it by epsilon in percents

38
Q

Inequality

A

Call the function and use logical NOT operator

39
Q

Approximately equal()

A

Will work in most cases, but not well when the numbers aproach zero

40
Q

Logical operators

A

To test multiple conditions

41
Q

C++ logical operators

A

Logical NOT!, OR||, AND&&

42
Q

Logical not

A

Flips a boolean value from true to false and vice versa

43
Q

Logical not with a result of operators

A

The operators and operands need to be in parenthesis

44
Q

Logical or

A

Used to test whether either of two conditions is true, if either or both are true it returns true

45
Q

Logical and

A

Used to test whether both operands are true

46
Q

Short circut evaluation

A

Used for optimization, when operator returns a value only on the basis of the evaluation of the first operand

47
Q

Mixing logical and and or

A

And has higher precidence so it will evaluate first unles parenthesized, also evaluates from right to left

48
Q

De Morgan’s law

A
Distribution of logical not can't be done like
*!(x&&y)=!x&&!y
You must flip logical Not and And like
*!(x&&y)=!x||!y
*!(x||y)=!x&&!y
49
Q

Logical exclusive XOR operator

A

Not in c++, it can be mimicked with logical not operator
It is used to test whether odd number of conditions are true, if we don’t work with boolean we can static_cast them into boolean.