Home » Uncategorized » Passing Array Elements to Functions in C

Passing Array Elements to Functions in C


// #define CALL_BY_VALUE
#define CALL_BY_REFERENCE

#ifdef VALUE
/* Call by Value */
#include <stdio.h>

void function (int y);

int main(void) {
	int i, x[2] = {4, 10};

	for (i=0; i<2; i++)
		function(x[i]);

	return 0;
}

void function (int y) {
	printf("%d\n", y);
}
#endif

/* Call by Reference */
#ifdef CALL_BY_REFERENCE
#include <stdio.h>

void function (int *y);

int main(void) {
	int i, x[2] = {4, 10};

	for (i=0; i<2; i++)
		function(&x[i]);

	return 0;
}

void function (int *y) {
	printf("%d\n", *y);
}
#endif
How to broadcast in NumPy arrays
How to broadcast in NumPy arrays

Leave a Comment

Sign up to our newsletter!