
#include <stdio.h>
void passByValue(int i); (Prototype)
void passByAddress(int*i);
int main()
{
int coffee = 20; (pass this value through 2 functions)
passByValue(coffee);
printf("Passing by value, coffee is now %d\n", coffee);
passByAddress(&coffee); ( here we have to toss in the memory address to function)
printf("Passing by address, coffee is now %d\n", coffee);
return 0;
}
void passByValue(int i){ (passed the variable)
i = 99;
return;
}
void passByAddress(int*i) { (pointer - points to a memory address. points to the memory address of coffee)
*i = 64; (Whenever you do that you have to Dereference it)
return;
}
Passing by value, coffee is now 20
Passing by address, coffee is now 64
Comments
Post a Comment