w05-bsc-function-basics-2
Function basics
In this example, we explore the basics of passing and returning pointers either by value or by reference.
Go into tehpc/basics/
. Consider the following code:
bsc_functions_2.cpp
Compile the code
- going into the
tehpc/build/
folder (possibly in another terminal) - compile with the following command:
g++ -Werror -Wpedantic -g -o bsc_functions_2 ../basics/bsc_functions_2.cpp
.
If you compile on Mac, consider adding the following compile option -std=c++17
.
When you run the code, an error occurs Segmentation fault (core dumped)
after computing the dot product using function
dumbDotProduct
. Analyze why this happens and try to fix it.
Run valgrind
and observe HEAP MEMORY
(you may want to post a screenshot of this in your MR).