Syntax

Add(a, b) // a and b are the parameters 

Calling a function in C program

Add.c

#include <stdio.h>  
int add(int a, int b);
void main()
{

int sum;
int a, b;
printf(" Enter the first and second number \n");
scanf("%d %d", &a, &b);
sum = add(a, b); // call add() function
printf( "The sum of the two number is %d", sum);
}
int add(int n1, int n2) // pass n1 and n2 parameter
{
int c;
c = n1 + n2;
return c;
}

Output

Call by value

Call by Value in C programming

Call_Value.c

#include <stdio.h>  
int main()
{
int x = 10, y = 20;
printf (" x = %d, y = %d from main before calling the function", x, y);
CallValue(x, y);
printf( "\n x = %d, y = %d from main after calling the function", x, y);
}
int CallValue( int x, int y)
{
x = x + 5;
y = y + 5;
printf (" \nx = %d, y = %d from modular function", x, y);
}

Output

Call By Reference

Call by Reference in C programming

Call_Ref.c

#include <stdio.h>  
int main()
{
int x = 10, y = 20;
printf (" x = %d, y = %d from main before calling the function", x, y);
CallValue (&x, &y);
printf( "\n x = %d, y = %d from main after calling the function", x, y);
}
int CallRef( int *a, int *b)
{
*a = *a + 5;
*b = *b + 5;
printf (" \nx = %d, y = %d from modular function", *a, *b);
}

Output

Categorized in:

C

Tagged in:

, , , , , , , , , , , , ,

Share Article:

Leave a Reply

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock