C Arrays As Parameters

Beginner
6 min read
Updated: Nov 2026
1 example

What Is Arrays As Parameters?

When you pass an array, C passes a pointer to its first element. int a[] and int *a mean the same in a parameter list. The function sees no length, so pass it separately, and remember that changes affect the original array.

Remember
int sum(const int a[], size_t n);   /* same as const int *a */
void scale(int a[], size_t n, int k);

sum(values, 5);       /* array decays to &values[0] */

Cheat Sheet

Keep these facts handy while you work with Arrays As Parameters in C.

TopicDetail
DecayArray name becomes a pointer
LengthPass it as a separate parameter
sizeofsizeof a in the callee is the pointer size
Read-onlyUse const for input arrays

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Variadic Functions.

Example 1 — Sum and modify an array in place

The function edits the caller's array through the pointer.

C
#include <stdio.h>

int sum(const int a[], int n) {
    int total = 0;
    for (int i = 0; i < n; i++) total += a[i];
    return total;
}

void double_all(int a[], int n) {
    for (int i = 0; i < n; i++) a[i] *= 2;
}

int main(void) {
    int v[] = {1, 2, 3, 4, 5};
    printf("sum = %d\n", sum(v, 5));
    double_all(v, 5);
    for (int i = 0; i < 5; i++) printf("%d ", v[i]);
    printf("\n");
    return 0;
}

How It Works

  1. sum takes const int a[], so it cannot change the data.
  2. double_all modifies the original elements.
  3. The length 5 travels as a separate argument.

Edge Cases & Pitfalls

Check these before relying on Arrays As Parameters in real programs.

sizeof

sizeof inside the function

sizeof a / sizeof a[0] is wrong in the callee. Compute the length in the caller.

bounds

Passing the wrong length

A length larger than the array reads or writes past the end.

Key Takeaways

  • Pointer: arrays pass as addresses.
  • Length: always send it.
  • const: protect input arrays.

One line: When you pass an array, C passes a pointer to its first element.

Frequently Asked Questions

The array itself is not copied. The array name decays to a pointer to its first element, so the function can modify the original elements.
Give every dimension except the first: void f(int m[][3], int rows). The column count must be known to compute addresses.
Continue with "C Variadic Functions" next. Accept a variable number of arguments with stdarg.h. The C Functions hub lists every topic in order.

Next: Variadic Functions

Accept a variable number of arguments with stdarg.h.

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful