Navigation



3.x — Comprehensive Quiz

Quick Review

Always use parenthesis to disambiguate the precedence of operators if there is any question or opportunity for confusion.

The arithmetic operators all work like they do in normal mathematics. The Modulus (%) operator returns the remainder from an integer division. Beware about rounding or sign errors when the operands of integer division and modulus are negative.

The increment and decrement operators can be used to easily increment or decrement numbers. Beware of side effects, particular when it comes to the order that function parameters are evaluated.

Relational operators can be used to compare floating point numbers. Beware using equality and inequality on floating point numbers.

Comprehensive quiz

1) Evaluate the following:

a) (5 > 3 && 4 < 8)
b) (4 > 6 && true)
c) (3 >= 3 || false)
d) (true || false) ? 4 : 5

2) Answer the following:

a) 7 / 4
b) 14 % 5

3) Convert the following from binary to decimal:
a) 1101
b) 101110

4) Convert the following from decimal to binary:
a) 15
b) 53

5) Why should you never do the following:
a) int y = foo(++x, x);
b) int x = 7 / -2;
c) int x = -5 % 2;
d) float x = 0.1 + 0.1; if (x == 0.2) return true; else return false;
e) int x = 3 / 0;

Solutions

1) Show Solution

2) Show Solution

3) Show Solution

4) Show Solution

5) Show Solution

4.1 — Blocks (compound statements) and local variables
Index
3.8 — Bitwise operators

3 comments to 3.x — Comprehensive Quiz

You must be logged in to post a comment.