Functions and everyday data
Splitting programs into functions, passing data efficiently with references, and working with text, lists and memory.
About 14 hours of study
Learning objectives
- Write and overload functions
- Pass by value and by reference appropriately
- Use string and vector
- Explain pointers and heap memory
Lessons
- 1
Functions in C++
Write functions with parameters and return values, give parameters default values, and overload one name for different types.
- 2
References Intermediate
Give a variable a second name, let functions change their caller's variables, and pass large values without copying them.
- 3
The string class
Work with std::string: length, characters, joining, searching and cutting, and pulling words apart with string streams.
- 4
Vectors
Store lists that grow with std::vector: adding and removing items, looping safely, sorting, and two-dimensional tables.
- 5
Pointers and memory Intermediate
Addresses and pointers, nullptr, new and delete, and why modern C++ usually lets containers manage memory for you.
Module practice
- C++: A function that answers yes or noEasy
- C++: Overloaded largestMedium
- C++: Fast powerHard
- C++: Change it through a referenceEasy
- C++: Two answers through referencesMedium
- C++: Tidy a list of wordsHard
- C++: Count a letterEasy
- C++: Title CaseMedium
- C++: Words in a lineHard
- C++: Sum and averageEasy
- C++: Remove the even numbersMedium
- C++: Rotate a tableHard
- C++: Change it through a pointerEasy
- C++: An array from newMedium
- C++: A list with new and deleteHard