

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Welcome to Memory Management
incomplete
2: C Program Structure
incomplete
3: Interpreted Quiz
incomplete
4: C Is Compiled
incomplete
5: Comments
incomplete
6: Basic Types
incomplete
7: Strings
incomplete
8: Printing Variables
incomplete
9: Compilation: Types
incomplete
10: Variables
incomplete
11: Constants
incomplete
12: Functions
incomplete
13: Void
incomplete
14: Unit Tests
incomplete
15: Math Operators
incomplete
16: If Statements
incomplete
17: Logical Operators
incomplete
18: Ternary
incomplete
19: Type Sizes
incomplete
20: Sizeof
incomplete
21: For Loop
incomplete
22: While Loop
incomplete
23: Do While Loop
incomplete
24: Pragma Once and Header Guards
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
All the same operators you'd expect exist in C:
x + y;
x - y;
x * y;
x / y;
If you're coming from Python, +=, -=, *=, /= are all the same.
In addition, there are also the ++ and -- operators:
x++; // += 1
x--; // -= 1
The name of C++ is a bit of a joke by the creator, it's meant to be "incremented C" or "better C".
These increment (++) and decrement (--) operators can be used in two forms: postfix and prefix.
Postfix (x++ or x--): The value of x is used in the expression first, and then x is incremented or decremented. For example:
int a = 5;
int b = a++; // b is assigned 5, then a becomes 6
Prefix (++x or --x): x is incremented or decremented first, and then the new value of x is used in the expression. For example:
int a = 5;
int b = ++a; // a becomes 6, then b is assigned 6
I generally avoid prefix operators. If I want to increment a variable but keep the original value, I do that in two steps. Postfix is more common, especially in loops, which we'll get to.
Complete the snek_score function in exercise.c. Sneklang is unique™ in that its toolchain gives developers a "project score" that's dependent on how maintainable and "high quality" their codebase is. The larger the score, the harder it is to work in the project. The score is calculated as follows:
You can convert an integer to a float by casting it:
int x = 5;
float y = (float)x;