Call by reference

In call-by-reference evaluation (also referred to as pass-by-reference), a function receives an implicit reference to a variable used as argument, rather than a copy of its value. This typically means that the function can modify (i.e. assign to) the variable used as argument—something that will be seen by its caller. Call-by-reference can therefore be used to provide an additional channel of communication between the called function and the calling function.
The call by reference mechanism modifies the passed value to local and global terms.


// type and declaration of function is defined first if function is 
// other than of integer type
void square(int*);  // void type, so declaration is compulsory
// paramater of type to integer to pointer
int main( ) 
    int num;
    printf("Enter number ");
    square(&num); // calling function square refering by address of num (& num)
    printf("number after modification %d",num); // value of num is not affected
   return 0;

void square(int *number)
    // value modified locally, no effect to passed value
    *number = *number + 10;
    printf("local value %d\n",*number);

You may also like...