Task 1b: Understanding Pointers - Add
Task Description
Complete the definition of function add by editing the file add.cpp
according to its specified pre- and post conditions.
We provide a test program using the implemented function to add two values given by the user.
Input
Integers a, b.
For example
21 35
Output
The test program prints the sum of a and b.
For example, for the input given above this value is 56.
Solution
#include "add.h"
// PRE: a, b, and res are valid pointers to integer values.
// POST: integer at location res contains the result of adding the integer at
// location a and the integer at location b.
void add(int *res, const int *a, const int *b) { *res = *a + *b; }
Made by JirR02 in Switzerland 🇨🇭