ctf Lesson 2 5 min read

CTF: Expressions & Type Conversion

2 challenges — Week 4

Expressions & Type Conversion Challenges

2 challenges Week 4 Week 4 (Operators and Expressions)

Expression evaluation exercises testing operator precedence, type conversion, and math library functions in C. These trace-style challenges train you to read C expressions the way the compiler does — left to right, respecting precedence rules that differ from what you learned in Java.

Before you start: Make sure you understand C’s integer division rule. 7 / 2 is 3 in C, not 3.5. The result is always truncated toward zero when both operands are integers. If either operand is a double, the division becomes floating-point.


Difficulty Breakdown

Level Count
Beginner 2

Challenges

1. Expressions1

Difficulty: Beginner Time: ~5 min Type: expression evaluation

Trace the evaluation of the following expressions, and give their resulting values. Make sure to give a value of the appropriate type (such as including a .0 at the end of a double).

Concepts: operator precedence (*, /, % before +, -), integer arithmetic vs floating-point arithmetic, modulo operator (%), implicit type promotion (int to double in mixed expressions), integer division truncation

Practice on CodeStepByStep


2. Math Expressions

Difficulty: Beginner Time: ~5 min Type: expression evaluation

Trace the evaluation of the following expressions, and give their resulting values. Make sure to give a value of the appropriate type (such as including a .0 at the end of a double).

Concepts: math library functions (abs, pow, sqrt, ceil, floor, min), function composition (nested function calls), return types of math functions, understanding ceil vs floor rounding behavior, negative number handling in math functions

Practice on CodeStepByStep