From C to C++

What C++ adds to C for everyday code: streams for input and output, the string class, references, overloaded functions and default arguments.

About 5 hours of study

Learning objectives

Lessons

  1. 1

    From C to C++

    cout and cin, using namespace std, bool and the string class: what C++ adds on top of the C you know.

  2. 2

    References, overloading and default arguments

    A reference is another name for a variable; one function name can have several versions; parameters can have default values.

Module practice

Module quiz

1. Which header gives you cin and cout?
2. Which line reads a whole line of text, spaces included, into the string s?
3. int x = 3; int& r = x; r++; What is x now?
4. string a = "cat"; string b = a + "s"; What is b.length()?
5. A function is declared void f(int a, int b = 5). Which call is not allowed?
6. Why is a large object usually passed as const T&?
7. There are two overloads, area(int) and area(double). Which one does area(2.5) call?

Classes and object lifetime ›