Last active
November 26, 2022 00:52
-
-
Save joegasewicz/2b7dcabe7a81f54562af79e71535b7f8 to your computer and use it in GitHub Desktop.
Pass By Reference
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
void square_num(int *num); | |
int main() | |
{ | |
/* ====================================================================== */ | |
/* Pass By Reference */ | |
/* ====================================================================== */ | |
// C exclusively passes by value but simulates passing by reference because | |
// it's a copy (they are local variables). | |
int num = 5; | |
square_num(&num); | |
printf("result = %d\n", num); | |
return 0; | |
} | |
void square_num(int *num) | |
{ | |
*num = (*num)*(*num); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment