Programming foundations

Stage 1 · Lesson 2 of 8

Types, variables and input

Your first language

C++ is and close to the hardware, so have fixed sizes and real limits. An int is usually 32 bits and cannot go past about 2.1 billion. Going past that limit is .

For a signed int it is , meaning the language promises nothing, so it is not a wraparound you can rely on. double holds decimals, bool holds true or false, char holds a single byte and std::string holds text.

Always initialise variables, ideally with braces, as in int count{0}. An uninitialised local variable holds garbage: whatever was in that memory before. Integer division cuts off the decimal part, so 7 / 2 is 3.

auto lets the compiler work out a type, which is then fixed. Read with std::cin >> x and check that it worked, because typing "abc" into an int puts cin into a failed state.

A question to check yourself, an AI practice session and 3 cheat sheet entries come when you add the roadmap to your account. Add it

Resources for this stage

Start with

  • CourseFree
    LearnCpp.com

    LearnCpp.com · Beginner

    Free, current and careful: chapters 0 to 16 take you from setup to references and std::vector

Practise

  • Small exercises in your language track, with free feedback from a human mentor

Keep handy

  • The standard library reference: check std::vector and std::string pages as you use them

  • Quick syntax lookups and an online compiler for testing a snippet on a shared computer

Mark this stage as not done?