Lesson 4 of 23

Operators and Type Casting

9 min 20 XP

Dividing two ints drops the decimal part: 7 / 2 is 3. % gives the remainder: 7 % 2 is 1. Cast with (double) when you need a decimal answer.

Example: edit me and press Run

Output Loading C (first time takes a few seconds)
Press Run to see the result here.

++i increments first and then gives the value; i++ gives the old value and then increments. A very popular C interview question.

Challenge

+20 XP

Read a number of seconds and print it as hours:minutes:seconds. Input: 3725 → Output: 1:2:5

Output Loading C (first time takes a few seconds)
Press Run to see the result here.