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){
     statement
 }

Example: How to add two numbers using call by reference in c.

#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("Sum is:%d", s);

    return 0;
}

Output:

Enter two numbers:10 20                                                                                                                
Sum is:30