Skip to content

Instantly share code, notes, and snippets.

@sojohnnysaid
Last active January 19, 2021 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sojohnnysaid/5c9dfdcd7d2002ba56e9b148cdbd3474 to your computer and use it in GitHub Desktop.
Save sojohnnysaid/5c9dfdcd7d2002ba56e9b148cdbd3474 to your computer and use it in GitHub Desktop.
#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