C Program to add two numbers using call by Reference


In this program, You will learn how to add two numbers using call by Reference in C.


Call by Reference

void sum(int a,int b,int *s){ }


Example: How to add two numbers using call by Reference in C

Run it Now
#include<stdio.h>

void sum(int a, int b, int *s) {
    *s = a + b;
}

int main() {

    int a, b, s;

    printf("Enter two numbers : ");
    scanf("%d%d", &a, &b);

    sum(a, b, &s);
    printf("\nThe sum is : %d", s);

    return 0;
}

Output:

Enter two numbers : 20 30
The sum is : 50