Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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
You can’t perform that action at this time.