Calling Function : Sample Code in C Programming
Calling Function in C : Sample Code
#include<stdio.h>
#include<conio.h>
int sum(int,int);
void main()
{
int a,b,c;
printf("\nEnter the two numbers : ");
scanf("%d%d",&a,&b);
c = sum(a,b);
printf("\nAddition of two number is : ");
getch();
}
int sum (int num1,int num2)
{
int num3;
num3 = num1 + num2 ;
return(num3);
}
Output :
Enter the two numbers : 12 12
Addition of two number is : 24
Analysis of Code : Calling Function
Syntax : Calling Function in C
function_name(Parameter1 ,Parameter2 ,....Parameter n);
- In the above example sum(a,b); is function call .
- a,b are parameters passed to function ‘sum’
- Function call should be made by ending Semicolon
Dissecting a C Program
Calling a Function :
- Call a C function just by writing function name with opening and closing round brackets followed with semicolon.
- If we have to supply parameters then we can write parameters inside pair of round brackets.
- Parameters are optional.
Call Function without Passing Parameter :
display();
Passing 1 Parameter to function :
display(num);
Passing 2 Parameters to function :
display(num1,num2);