Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void passByValue(int i);
- void passByAddress(int *i);
- int main()
- {
- //up to now we have been passing a copy of that variable in
- //that was called passing by value
- //we can pass in the actual variable by passing the address
- int tuna = 20;
- passByValue(tuna);
- printf("Passing by value, tuna is now %d \n", tuna);
- //not passing in a copy, but the actual variable
- passByAddress(&tuna);
- printf("Passing by address, tuna is now %d \n", tuna);
- return 0;
- }
- void passByValue(int i){
- i = 99;
- return;
- }
- void passByAddress(int *i){
- //dereference to get the value
- *i = 64;
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement