CJCoding With Joseph
15free / daySign inCreate account

Value, Reference, and Pointer Side by Side

main is already written:

    int a = 5, b = 5, c = 5;
    addByValue(a);
    addByReference(b);
    addByPointer(&c);

Fill in the bodies of addByValue(int n), addByReference(int &n) and addByPointer(int *n) so each one adds 100 to the number it was handed. main then prints the three variables.

The program must print exactly these three lines (see Expected Output).

Expected Output:

value: 5
reference: 105
pointer: 105

= newline. The output ends with a newline — print one after the last line.

Hints2 available
Topics:
Pointers
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.