Created
November 27, 2023 12:16
-
-
Save EteimZ/9501b78ca343746eb15c45d205e2738f to your computer and use it in GitHub Desktop.
Demonstraing passing by reference in C.
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> | |
| void incr(int *x){ | |
| *x += 1; | |
| } | |
| int main(){ | |
| // initialize i to be equal to 6 | |
| int i = 6; | |
| printf("i = %d\n", i); | |
| // increment it by passing it's value by reference | |
| incr(&i); | |
| printf("i = %d\n", i); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment