Answers/Solutions to Exercises in Chapter 5, Exercise 10

E10: Rewrite the simple C function below that receives an integer parameter so that it emulates receiving of the parameter by "reference".
    void doit(int x)
    {
        printf("%d\n",x);
        x++;
        printf("%d\n",x);
    }

A10: void doit(int* x)
    {
        printf("%d\n",*x);
        (*x)++;                  // careful here, why not *x++ ?!
        printf("%d\n",*x);
    }

Back to Answers/Solutions Index                          Back to Answers/Solutions for Chapter 5 Index