Summary
In this lesson, you learned that:
- A program is a series of statements that run one after another, from top to bottom. Before it runs, the compiler checks it and translates it.
- Every program has a frame:
#include <stdio.h>and the functionint main(void) { }. The program starts inmain, the statements go between its curly braces, andreturn 0;at the end says that the program ended fine. - Every statement ends with a semicolon
;. C treats uppercase and lowercase letters as different. printf("...");prints a text in double quotes. It doesn't start a new line by itself:\nin the text ends a line.\"prints a quote and\\a backslash.%din the format string marks the place for a whole number, which you write after a comma:printf("%d\n", 5 + 3);prints8, butprintf("5 + 3\n");prints5 + 3. C calculates with+,-,*and parentheses.- Comments start with
//and last until the end of the line, or they go between/*and*/. The compiler ignores them. You can also use them to switch code off (comment it out). - The error message
main.c:LINE:COLUMN: error: descriptionsays where the mistake is and what's wrong. When there is an error, the program doesn't run at all. Always fix the first error first, and run the program again.
In the next lesson, Variables and Types, you'll learn to store values in variables and calculate with them.
Instructions
Before you go on, try it all out on a small task: the final screen of a game. Below the heading, print the player's nickname in quotes, the points from both rounds and their total, so that the program prints:
GAME OVER
Player: "Rocket"
Round 1: 1250
Round 2: 300
Total: 1550Don't write the number 1550 yourself: print it with %d and let C add up 1250 + 300.
Above the printf that adds up the points, write a comment that says what it does.
Start programming for free
7/7