C calling function

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 : %d",c); 
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);
  1. In the above example sum(a,b); is function call .
  2. a,b are parameters passed to function ‘sum’
  3. Function call should be made by ending Semicolon

Dissecting a C Program

Calling a Function :

  1. Call a C function just by writing function name with opening and closing round brackets followed with semicolon.
  2. If we have to supply parameters then we can write parameters inside pair of round brackets.
  3. Parameters are optional.

Call Function without Passing Parameter :

display();

Passing 1 Parameter to function :

display(num);

Passing 2 Parameters to function :

display(num1,num2);