Operations Flashcards

1
Q

++ / - - operator

++variable
Variable++
- - variable
Variable- -

A

+1 , -1 to variable value

Relative to order with variable

I.e number++&raquo_space; prints the number then adds 1

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

~

A

Bitwise complement

Flips value of bitwise

1111&raquo_space; 0000

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

!

A

Logical negation

Inverts Boolean logic

True&raquo_space; false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
\+
- 
*
/
%
A
Addition
Subtraction 
Multiplication 
Division 
Modulus 

Modulus&raquo_space; remainder

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

What is the modulas

A

Modulus is just the remainder

So 6/3 is 0 but 5/2 is 5

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

==

!=

A

Equal to

Not equal to

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

<
>
<=
>=

A

Less than
Greater than
Less than or equal to
Greater than or equal to

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

&&
||
!

A

&& = And&raquo_space; result will be true if both expressions are true

Int num1 = 6;
Int num2 = 5;
Print(Num1 < 10 && num2 < 5);

Output = false

|| = Or&raquo_space; result will be true if any expression is correct

Print(Num1 < 10 || num2 < 5);

Output = true

! = NOT&raquo_space; result will be false if the expression is true and vice versa

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

Logic table

A B A&&B A||B. A !A
True true True
True false. False
False true
False false

A
A        B, A&&B, A||B.         A       !A
True true true true          True  false
True false false true       False true
False true false true
False false false false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Ternary operator

A

Single line replacement for
If-then-else statements and acts upon three operands

? : ;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
Assignment operators
= 
\+= 
-=
*=
/=
A

= assigns value on right to variable on left
+= adds the current value of variable on left to value on right and returns result to variable on the left
-= subtracts current value of variable —“—
*= multiplies current value of variable —“—
/= divides current value of variable —“—

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

Bitwise counting

Bitwise most likely won’t be tested

A

Manipulate the individual bits of a number

Recall: 11001 = 2^4+ 2^3 + 2^0

Last digit is 2^0 and the power increases as you go left, if 0: spot is false, if 1: spot is true

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

Bitwise operators

A

Bitwise OR: | if either bit is 1 then it
gives 1 if not zero
10|5 (1010|0101) = 1111 or 15

Bitwise AND: & If both bits are 1 then it gives 1 if not 0
10&5 (1010&0101) = 0000 or P

Left shift operator: &laquo_space;left shifts the bits of the first operand and the amount shifted is by the second operand (fills spot with zero)

I.e 10«1
1010 becomes 10100 which is 20

Right shift operator:&raquo_space; opposite of left shift, fills 0 if positive operand or 1 if negative operand.
10»1
1010 becomes 0101 which is 5

Unsigned right shift:&raquo_space;> right shift operator but no correction for negative numbers

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

Precedence (order) of operators

Not too important to know specifics, just a vague generalisation

A

1) Brackets
2) postfix (++.- -)
3) prefix, unary (++, - -, +,-,~,!)
4) multiplication (,/,%)
5) additive (+,-)
6) shift (<>,»>)
7) relational (,<=,>=)
8) equality (==,!=)
9) logicaL AND (&&)
10) logical OR (||)
11) ternary ?:
12) assignment (=,+=,-=,
=,«=,»=,»>=)

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

Logical order and bitwise order

A

Logical operators are lazy and won’t check the second statement if first statement is false, so can affect any operation performed in statement

Difference between bitwise or and logical or and bitwise AND and logical AND

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