 This work is licensed under a Creative Commons Attribution 3.0 Unported License.
Original author: John Clements

The first step in any programming task is to think about the kinds of data that you need, and the first step in learning a new programming language is to understand the kinds of data that it can represent. These are called "values." In C, the most basic set of values are the whole numbers, or "integers." 13 is an integer, and so is 0. Try entering an integer in this box: If you like, you can try a bunch of different integers.

Secret Note for Especially Advanced People: Are there things that you expect to be integers that aren't? See if you can figure out why negative numbers don't parse (i.e. get interpreted) as integers. text-field-2

Arithmetic operations
The C language has a variety of boolean operations, including addition (+), subtraction (-), multiplication (*), and division (/). Make sure you can find all of these on the keyboard. These operators behave more or less as you might expect, with a few gotchas. To add `3` and `4` together, for instance, you can write `3 + 4` . Write an arithmetic expression that uses addition to add two numbers: text-field-3
So, what are the gotchas? The biggest one has to do with integer division. In C, dividing an integer by an integer produces another integer. This works as you might expect for quotients like `4 / 2`, but when the denominator does not evenly divide the numerator, C rounds toward zero. (What if one is negative? Don't ask. Please.) Okay, quiz time: fill in the integers that result from the following division operations: `10 / 5` pattern 2 text-field-4 `9 / 4` pattern 2 text-field-5 `3 / 12` pattern 0 text-field-6

Nested Operations
Like normal mathematical notation, multiple elements may be joined together using arithmetic operators. For instance `3 + 4 + 5` is a fine expression, and so is `20 * 14 * 3`. Write the C expression that adds fifteen, sixteen, and twenty-three: pattern 15+16+23 text-field-7 What about operators such as division and subtraction? These operators are not associative. That is, `(20 / 19) / 19` does not produce the same value as `20 / (19 / 19)`. In this case, C's default is to be "left-associative"; that is, the leftmost operator binds more tightly. So the expression `20 / 19 / 19` is evaluated as `(20 / 19) / 19`. What if that's not what you want? Well, you can use parentheses-as in the examples above-to get the meaning you want. Combining different operators is also possible, and gives rise to similar questions. For instance, the expression `3 + 4 * 5` might evaluate either to 35 or to 23. In this case, C uses rules of "precedence" to determine which operators "bind more tightly". C follows the standard convention that operators such as multiplication and division have higher precedence than addition, so `3 + 4 * 5` evaluates to 23. Precedence rules and associativity are complex; in general, the best advice is simply to parenthesize whenever you're unsure. Translate the given English into a C expression, and then enter the expected integer result: English Statement C Expression Expected Result ten plus the result of 4 divided by 2 pattern 10+(4/2) text-field-8 pattern 12 text-field-9 the result of four plus five, divided by three pattern (4+5)/3 text-field-10 pattern 3 text-field-11 four times the result of five minus two, divided by six pattern (4*(5-2))/6 text-field-12 pattern 2 text-field-13