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
 }

C Program to add two numbers using call by reference

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