Skip to content

Instantly share code, notes, and snippets.

@joegasewicz
Last active November 26, 2022 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joegasewicz/2b7dcabe7a81f54562af79e71535b7f8 to your computer and use it in GitHub Desktop.
Save joegasewicz/2b7dcabe7a81f54562af79e71535b7f8 to your computer and use it in GitHub Desktop.
Pass By Reference
#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