Exercises


  • What is the difference between:
    void chimichanga(int taco, int nacho)
    
    and
    void chimichanga(int *taco, int *nacho)
    
    What happens if you modify a variable in the first? What about the second? Why does this happen?
  • Your office has asked you to come up with a way to pass an array to a function and have the function multiply everything in the array by 5. Luckily, you've read this chapter, so impress your boss and try it!
  • Write a function that is passed a pointer-to-int and have it return a value inside the integer.
  • Try doing the above example with reference variables. Which one do you like better?
  • Try creating an array of pointers to a struct. Write a for loop that runs new on every cell of the array to fill it up with pointers to real structures. Pass the array to another function and have it print out the contents of each structure.


Table of Contents

Parameter Passing | Passing Pointers | Passing Arrays | Reference Variables
Exercises