Computing the sum of two integers (C++)

By Patrick Celedio

Blog Logo Image

In order to write a function that computes the sum of two integers, all we need are three int variables: two that store each addend, and one that will be used to store the sum.

A very simple program, one may write this up:

1 2

Which will definitely work. However, we can omit the line containing ‘c=a+b’ as we are allowed to return formulas or equations.

3 4

From here, we save a line of code for a function that is already so simple.