References and argument passing

This lesson contains approximately 38 minutes of video content.

Initialization of objects and function calls

References

Pass by reference

When do we pass arguments by reference?

Guidance for passing arguments

Activity: Append an array's content to an std::vector

Graded Playground Autograder

Activity Prompt:

In this problem, you will implement the function AppendArrayToVector. This function will append the contents of an integer array to the back of an integer vector.

AppendArrayToVector's return type will be void, and it will specify three parameters: array, array_size, and vector typed int[], unsigned int, and std::vector<int> respectively. Following the conventions outlined in the lessons, you must correctly determine how each argument should be passed to AppendArrayToVector: by value, reference, or constant reference.

You will define AppendArrayToVector such that each array element is appended to the back of the std::vector<int>. You will append the elements residing in the array in ascending index order. You will begin at the array's index 0 and visit each element in order.

#include <iostream> #include "solution.hpp" int main() { }
#ifndef SOLUTION_HPP #define SOLUTION_HPP // what includes do you require? // function declarations below. #endif
#include "solution.hpp" // function definitions below.