Free tutorials & notes in Hindi & English · Clean code examples · Mobile friendly learning
🟡 Intermediate  ·  Lesson 18

Function Arguments & Return

Written and reviewed by · Senior IT Faculty · 15+ years’ experience

Function Arguments (Parameters)

When you call a function, you can pass data to it. The values you pass are called arguments. The variables that receive them in the function definition are called parameters.

Accuracy first

C always passes arguments by value. If you pass an integer, the integer value is copied. If you pass an address, the pointer value is copied; dereferencing that pointer allows the function to access the caller's object. Textbooks often call the second pattern “pass by reference,” but C has no separate reference-parameter mechanism.

Pass by Value

A copy of the argument's value is passed. Changes inside the function do NOT affect the original variable.

C Language – Pass by Value Demo
#include <stdio.h>

void doubleIt(int n) {    // n is a COPY of the argument
    n = n * 2;
    printf("Inside function: n = %d\n", n);
}

int main() {
    int x = 5;
    printf("Before call: x = %d\n", x);
    doubleIt(x);              // Passes a COPY of x
    printf("After call:  x = %d\n", x); // x unchanged!
    return 0;
}
Before call: x = 5 Inside function: n = 10 After call: x = 5
💡 Why x didn't change?

When you call doubleIt(x), C copies the value of x (which is 5) into the parameter n. The function works on its own local copy n, not on the original x. So x remains 5 after the call.

Pointer Arguments (Address Passed by Value)

Pass the variable's address. The function receives a copy of that address and can modify the original object by dereferencing the pointer. This technique is commonly described informally as pass by reference.

C Language – Pointer Argument Demo
#include <stdio.h>

void doubleIt(int *n) {   // n is a POINTER to the original
    *n = *n * 2;           // Modify value at the address
    printf("Inside function: *n = %d\n", *n);
}

int main() {
    int x = 5;
    printf("Before call: x = %d\n", x);
    doubleIt(&x);            // Pass ADDRESS of x
    printf("After call:  x = %d\n", x); // x IS modified!
    return 0;
}
Before call: x = 5 Inside function: *n = 10 After call: x = 10

Classic Example: swap() Function

C Language – Correct Swap
#include <stdio.h>

// WRONG: pass by value — doesn't work!
void swapWrong(int a, int b) {
    int temp = a; a = b; b = temp;  // Only local copies swapped
}

// CORRECT: pass addresses; pointer values are copied
void swapCorrect(int *a, int *b) {
    int temp = *a; *a = *b; *b = temp;
}

int main() {
    int x = 10, y = 20;
    swapWrong(x, y);
    printf("After swapWrong:   x=%d, y=%d\n", x, y);  // Still 10, 20
    swapCorrect(&x, &y);
    printf("After swapCorrect: x=%d, y=%d\n", x, y);  // 20, 10
    return 0;
}
After swapWrong: x=10, y=20 After swapCorrect: x=20, y=10

Arrays as Function Parameters

In a function parameter declaration, an array parameter is adjusted to a pointer to its first element. The pointer is passed by value, the complete array is not copied, and writes through that pointer can modify the caller's array. Pass the element count separately because the function does not automatically know the array length.

C Language – Array as Parameter
#include <stdio.h>

void printArray(int arr[], int n) {  // arr[] same as int *arr
    for (int i = 0; i < n; i++)
        printf("%d ", arr[i]);
    printf("\n");
}

void doubleArray(int arr[], int n) {
    for (int i = 0; i < n; i++)
        arr[i] *= 2;  // Modifies ORIGINAL array!
}

int main() {
    int nums[] = {1, 2, 3, 4, 5};
    printf("Before: "); printArray(nums, 5);
    doubleArray(nums, 5);
    printf("After:  "); printArray(nums, 5);
    return 0;
}
Before: 1 2 3 4 5 After: 2 4 6 8 10

Returning Multiple Values via Pointers

A function can only return ONE value. But using pointers, you can "return" multiple values.

C Language – Min and Max in one call
#include <stdio.h>

void minMax(int arr[], int n, int *minVal, int *maxVal) {
    *minVal = *maxVal = arr[0];
    for (int i = 1; i < n; i++) {
        if (arr[i] < *minVal) *minVal = arr[i];
        if (arr[i] > *maxVal) *maxVal = arr[i];
    }
}

int main() {
    int arr[] = {85, 32, 97, 45, 11, 78};
    int n = 6, minV, maxV;
    minMax(arr, n, &minV, &maxV);
    printf("Min = %d, Max = %d\n", minV, maxV);
    return 0;
}
Min = 11, Max = 97

Summary

FeatureOrdinary value argumentPointer argument
What is passedCopy of the valueAddress (pointer) of variable
Original modified?❌ No✅ Yes
Syntax (caller)func(x)func(&x)
Syntax (function)void f(int n)void f(int *n)
ArraysComplete array is not copiedArray parameter adjusts to pointer
  • C always passes by value — including when that value is a pointer
  • Pass an address and dereference the pointer when a function must modify the caller's object
  • An array parameter is adjusted to a pointer; pass its length separately
  • Pass pointers to "return" multiple values from a function

Authoritative References

References reviewed on 14 August 2026. Programs and explanations are original teaching material.

Frequently Asked Questions

What are function arguments in C?
Function arguments are the values you pass to a function when you call it, which the function receives through its parameters. For example in add(3, 5), the arguments 3 and 5 become the parameters inside the add function.
What is the difference between arguments and parameters?
Parameters are the variable names listed in the function definition, while arguments are the actual values passed in when the function is called. Parameters are the placeholders; arguments are what fills them for a particular call.
What is call by value in C?
Call by value means the function receives a copy of each argument, so changes made inside the function do not affect the caller's original variables. This is the default way C passes ordinary variables to functions.
Does C support true pass by reference?
No. C passes every argument by value. To let a function modify a caller object, you pass its address; the pointer value itself is copied, and dereferencing that pointer accesses the original object.
How do you pass an array to a function in C?
You pass the array by its name, which gives the function the address of its first element, so the function works on the original array rather than a copy. You usually also pass the size as a separate argument, since the length is not carried automatically.
Can a C function return a value?
Yes. A function's return type states what kind of value it gives back, and the return statement sends that value to the caller. A function declared void returns nothing, while one declared int returns an integer.
← Back to C Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 Live Code Editor

This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.