It sounds as if your instructor is confused.
With C, you can pass by reference, like this:
Code:
#include <stdio.h>
void pass_by_value(int number) // indicate an integer is being passed
{
printf("pass_by_value...\n", number) ;
printf("\tThe incoming number is %d\n", number) ; // num is 5
printf("\tThe address of number is %p\n", &number) ; // some address on the stack
number *= number ; // square it ;
printf("\tAfter squaring, number is now %d\n\n", number) ; // report new value
}
void pass_by_reference(int *number) // indicate a pointer is being passed
{
printf("pass_by_reference...\n") ;
printf("\tThe incoming number is %d\n", *number) ; // num points to 5, so use indirection
printf("\tThe address of number is %p\n", number) ; // same address as main()
*number *= *number ; // square it - have to use indirection ;
printf("\tAfter squaring, number is now %d\n\n", *number) ;
}
int main (int argc, const char * argv[]) {
int i = 5 ;
printf("main...\n") ;
printf("\tThe number is %d\n", i) ;
printf("\tThe address of number is %p\n\n", &i) ; // report it's memory address
pass_by_value(i) ; // pass the value of variable i
printf("main after calling pass_by_value...\n") ;
printf("\tThe number is now %d\n\n", i) ; // show i has not changed value
pass_by_reference(&i) ; // pass the address of variable i
printf("main after calling pass_by_reference...\n") ;
printf("\tThe number is now %d\n", i) ; // show the new value of i
return 0;
}
Here is the output. Note that with when passing by value, a new copy of the variable is created on the stack, as can be seen by its memory address being different than the address in main(), and any changes to it in the called function are not reflected in the calling function.
However, when passing by reference in C, any changes to the value are reflected in the calling function, because a new copy of the variable is not made on the stack - the calling function passed the pointer to variable to the called function.
Code:
main...
The number is 5
The address of number is 0xbffffa0c
pass_by_value...
The incoming number is 5
The address of number is 0xbffff9f0
After squaring, number is now 25
main after calling pass_by_value...
The number is now 5
pass_by_reference...
The incoming number is 5
The address of number is 0xbffffa0c
After squaring, number is now 25
main after calling pass_by_reference...
The number is now 25