codegurukool.com · Free coding tutorials & online compiler

Home › C Tutorial › Function parameters

Function parameters

Pass values and arrays.

Arguments are copied. An array parameter becomes a pointer, so pass the size too.

Example code

#include <stdio.h>
int sum(int a[], int n) {
  int s = 0;
  for (int i = 0; i < n; i++) s += a[i];
  return s;
}
int main() {
  int v[] = {1, 2, 3, 4};
  printf("%d\n", sum(v, 4));
  return 0;
}

Run this code in the online editor

← C functionsPass by reference →