3 Operators & Flow Control Flashcards

1
Q

Arthematic operators in C?

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

% operator in C?

A

A%B

remainder of the integer division of a/b

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

Microprocessor arithmetic problems?

A

Most simple processors cannot perform single instruction division or multiplication

Using the PIC, the XC8 compiler will break your maths down into multiple instructions, your code may no longer be deterministic!

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

Arithmetic: Repeat?

A

Division: Repeated Subtraction

Multiplication: Repeated Addition

Comments: Non-deterministic

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

What can it mean to be non-deterministic?

A

This means that it can exhibit different results for the same set of data. (Can be unaccurate)

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

Arithmetic: Shift?

A

Division: Right Shift

Multiplication: Left Shift

Comments: Only for powers of 2

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

Arithmetic: Newton Raphson?

A

Division: Newton Raphson

Multiplication: -

Comments: very fast, not accurate

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

Arithmetic: Shift +?

A

Division: -

Multiplication: Lift shift and add

Comments: Only for constants

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

C operator procedure?

A
  • Expressions are usually evaluated from left to right (associativity)
  • If an expression has different operators then precedence rules are applied
  • Brackets may be used to form sub-expressions that override precedence
  • For example arithmetic operators * / will be evaluated before + or – (think BIDMAS)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does C deal with Boolean variables?

A
  • Unlike some other languages C does not have a Boolean type
  • C uses int
  • Any non-zero value is interpreted as TRUE
  • Zero is interpreted as FALSE
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Relational operators in C?

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

Log Op: AND?

A

&&

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

Log Op: OR

A

||

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

Log Op: logical negation?

A

!

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

Logical negation?

A

(NOT Gate)

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

True/False?

A
17
Q

Examples of Logical operators?

A
18
Q

What are bitwise operators?

A

Operate on the individual bits of each variable, rather than the variable as a whole

19
Q

Bitwise operators in C?

A
20
Q

a=5

b=3

c = a&b?

A

Bitwise AND

a = 5(0b101)

b = 3(0b011)

c = 1 (0b001)

21
Q

a = 5

b = 3

c = a | b

A

Bitwise OR

a = 5(0b101)

b = 3(0b011)

c = 7 (0b111)

22
Q

a=5

b=3

c = ~a

A

Operation: Complement.

a = 5 (0b101)

b = 3 (0b011)

c = 250 (0b1111 1010)

23
Q

a =5

b=3

c = a << 2

A

Operation: Left Shift (*2)

a = 5 (0b101)

b = 3 (0b011)

c = 20 (0b10100)

24
Q

a= 5

b = 4

c = a >> 2

A

Operation: Right Shift(/2)

a = 5 (0b101)

b = 3 (0b011)

c = 1 (0b001)

25
Q

Bit-wise operators: AND?

A

&

26
Q

Bit-wise operators: EX-OR

A
27
Q

Bit-wise operators: OR

A

|

28
Q

Bit-wise operators: complement

A

~

29
Q

Bit-wise operators: shift left?

A

<<

30
Q

Bit-wise operators: shift right

A

>>

31
Q

The difference between bitwise and Logical?

A
32
Q

What is Non-linear execution?

A
  • Non-linear execution is caused by an instruction that modifies the Program Counter.
  • For example (in assembly): goto, call, btfss, btfsc
  • In C there are many instructions that cause non-linear execution,
33
Q

Instructions that cause non-linear execution in C?

A
34
Q

Example of conditional code in C?

A
35
Q

Example of loop structure in C?

A
36
Q

Example of a nested loop in C?

A