I have this homework problem:
Part A
Write a C program that tests whether or not the following data types are passed by reference or by value, and prints what it discovers out to the terminal:
- int
- array of ints
Hypothetically, if your program discovers that an int is passed by value and an array of ints is passed by value, then it should produce output like: int: pass-by-value array of ints: pass-by-value
The int I understand, but what I don't get is:
- I thought the only way to pass an array was to pass the address of the first value in the array
- does this count as passing by value or passing by reference? ( Pass an array to a function by value confused me)
- Hints on how I can do this? I'm assuming something like passing the reference to another function, manipulating it, and seeing if it changed, but I'm not sure....
Edit: might help if someone explained this to me with a concrete example, such as: Say I have an array of length 10 ints stored at memory location 0 (yeah, I know, not real life, but for the sake of the example...). What would it look like if that array was passed by reference? What would it look like if it was passed by value?