Facebook Page Twitter Page LinkedIn Page
× C Tutorial C Resources

To pass parameter(s) by reference in a function in C, the address of the parameter(s) should be used and to achieve this, parameter(s) should be passed by pointer. When passing the parameter(s) by pointer, all operation(s) performed on the passed parameter(s) is performed at its memory location inside the function. This means that any changes made to the parameter(s) inside the function will change the parameter(s) itself.


In the below example, the function called Square is created which takes argument as pointer and returns square of the passed argument. The function takes the address of the parameter and modify the parameter as square of itself at its memory location. In the main() function, when the passed argument is printed after calling the function Square, the value of the parameter get changed because it was changed at its memory location.

#include <stdio.h>
int Square(int *x); 

int main (){
    int x = 5;
    printf("Initial value of x: %i\n", x);
    printf("Value of x, after passed by reference: %i\n", x);
    return 0;

int Square(int *x){
    *x = (*x)*(*x);
    return *x; 

The output of the above code will be:

Initial value of x: 5
Value of x, after passed by reference: 25

❮ C - Functions