Write a program in C to add numbers using call by reference

Previous
Next

Solution:

  • Passing references(addresses) as parameters to function is called “Call By Reference”.
  • We need to specify the pointer type arguments in the called function to collect these references.
  • We can access the information(a, b) of calling function from called function using pointer variables(x, y).
#include<stdio.h>
int add(int* ,int*);
int main()
{
	int a, b, c;
	printf("Enter Two Values: \n");
	scanf("%d %d",&a,&b);
	c=add(&a, &b);
	printf("The Sum is: %d \n",c);
	return 0;
}
int add(int *x, int *y)
{
	int z;
	z=*x+*y;
	return(z);
}
Previous
Next

Courses Enquiry Form