Last active
January 19, 2021 22:52
-
-
Save sojohnnysaid/5c9dfdcd7d2002ba56e9b148cdbd3474 to your computer and use it in GitHub Desktop.
This file contains 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 set_int(int); | |
void set_array(int x[]); // a function prototype where the argument is an array of type int | |
int main(void) { | |
// When we pass an array to a function it works on the actual array. | |
// This is known as being passed by reference. | |
// A variable on the other hand is passed by value | |
int my_number = 10; | |
int my_array[] = {1, 3, 5, 8}; | |
set_int(my_number); | |
set_array(my_array); | |
printf("my number is %i and the first value in my array is %i\n", my_number, my_array[0]); | |
} | |
void set_int(int x) | |
{ | |
x = 88; | |
} | |
void set_array(int x[]) | |
{ | |
x[0] = 42; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment