Following a reassigned pointer parameter

An inventory program runs the following C code. Find the final values of a.units and b.units immediately before main returns. Report both quantities in inventory units as exact integers, to zero decimal places.


C
struct Stock {
    int units;
};

void redirect(struct Stock *p, struct Stock *other)
{
    p->units -= 3;
    p = other;
    p->units += 5;
}

int main(void)
{
    struct Stock a = {17};
    struct Stock b = {26};
    redirect(&a, &b);
    return 0;
}
Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Passing Structures to Functions Questions: