CS 70

Written Questions

Written Questions

This assignment includes written questions about a really useful debugging tool called valgrind. The questions can be completed individually or with your partner.

Before you do the written part, read about valgrind from the help pages:

  • Goat speaking

    Meh, I don't want to read right now, we're in the lab, ready to work on the coding part! Do we have to do the written questions first?

  • LHS Cow speaking

    No, you can dive into coding now and wait to do the written questions until later. But it's useful to know about valgrind when you need to debug your code, so you might not want to put it off until the last minute.

These questions use the programs in the exercises subdirectory of the assignment repository. For each one, compile with make and then run it under valgrind, reading the output carefully — valgrind gives a lot of output, but there are important clues buried in it. Ask for help if you have trouble interpreting it!

Question 1 – Exercise 1

Compile exercise01.cpp using make, then run:

valgrind --leak-check=full ./exercise01

Question 1.1

Which error, if any, does valgrind give for exercise01?

Question 1.2

What does valgrind tell you about where the problem occurs in the exercise01.cpp code, if there is one?

(Hint: if valgrind does not report any line numbers or function names, something is wrong! Did you compile using make? If not, make clean and then make and try again.)

Question 1.3

If applicable, explain how you would fix exercise01.cpp to resolve this error. If there is no error, you can write "n/a" below.

Question 2 – Exercise 2

Compile exercise02.cpp using make, then run:

valgrind --leak-check=full ./exercise02

Question 2.1

Which error, if any, does valgrind give for exercise02?

Question 2.2

What does valgrind tell you about where the problem occurs in the exercise02.cpp code, if there is one?

Question 2.3

If applicable, explain how you would fix exercise02.cpp to resolve this error. If there is no error, you can write "n/a" below.

Question 3 – Exercise 3

Compile exercise03.cpp using make, then run:

valgrind --leak-check=full ./exercise03

Note: If valgrind gives multiple errors, your answer should focus on the first one.

Question 3.1

Which error, if any, does valgrind give for exercise03?

Question 3.2

What does valgrind tell you about where the problem occurs in the exercise03.cpp code, if there is one?

Question 3.3

If applicable, explain how you would fix exercise03.cpp to resolve this error. If there is no error, you can write "n/a" below.

Question 4 – Exercise 4

Compile exercise04.cpp using make, then run:

valgrind --leak-check=full ./exercise04

Question 4.1

Which error, if any, does valgrind give for exercise04?

Question 4.2

What does valgrind tell you about where the problem occurs in the exercise04.cpp code, if there is one?

Question 4.3

If applicable, explain how you would fix exercise04.cpp to resolve this error. If there is no error, you can write "n/a" below.

Question 5 – Exercise 5

Compile exercise05.cpp using make, then run:

valgrind --leak-check=full ./exercise05

Question 5.1

Which error, if any, does valgrind give for exercise05?

Question 5.2

What does valgrind tell you about where the problem occurs in the exercise05.cpp code, if there is one?

Question 5.3

If applicable, explain how you would fix exercise05.cpp to resolve this error. If there is no error, you can write "n/a" below.

Question 6 – Exercise 6

Compile exercise06.cpp using make, then run:

valgrind --leak-check=full ./exercise06

Question 6.1

Which error, if any, does valgrind give for exercise06?

Question 6.2

What does valgrind tell you about where the problem occurs in the exercise06.cpp code, if there is one?

Question 6.3

If applicable, explain how you would fix exercise06.cpp to resolve this error. If there is no error, you can write "n/a" below.

To Complete This Part of the Assignment…

You'll know you're done with this part of the assignment when you've done all of the following:

(When logged in, completion status appears here.)