Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

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 function int main(void) { }. The program starts in main, the statements go between its curly braces, and return 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: \n in the text ends a line. \" prints a quote and \\ a backslash.
  • %d in the format string marks the place for a whole number, which you write after a comma: printf("%d\n", 5 + 3); prints 8, but printf("5 + 3\n"); prints 5 + 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: description says 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

  1. 1

    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: 1550

    Don't write the number 1550 yourself: print it with %d and let C add up 1250 + 300.

  2. 2

    Above the printf that adds up the points, write a comment that says what it does.

Back

9/9

  1. 1. Your First Program
  2. 2. More Lines
  3. 3. Quiz: New Lines
  4. 4. Quotes in Text
  5. 5. Text and Numbers
  6. 6. Comments
  7. 7. Reading Errors
  8. 8. Quiz: Spot the Mistake
  9. 9. Summary
Next

Try it yourself

Do this exercise right here in your browser. No account needed.