previous | index | next

Passing Structs to Functions

Now test with:

test_struct_clear.cpp
gameState state;

state.pile1 = 5;
state.pile2 = 8;
clear(state);

assert(state.pile1 == 0 && state.pile2 == 0);

Q: Output?

    Assertion `state.pile1 == 0 && state.pile2 == 0' failed.
Q: Why the failure?

A: A copy of the structure was passed to clear, modifications were made to the copy, and the original was not affected. The true assertion:
    assert(state.pile1 == 5 && state.pile2 == 8);

previous | index | next