FY_CPP_Functions
FY_CPP_Functions
Chapter 3
Introduction to C++
Functions
FUNCTION
• Sub program
– A self contained block of statements that performs a
particular task.
• Reusability
• Easy to read, write, debug.
• Maintenance & modification is easier.
• Reduces length of the program.
}
void main()
{
clrscr();
add(); Function Call
getch();
}
14/12/2022 Kaushik Panchal 9
#include <iostream.h>
#include <conio.h>
void add(); Function Declaration
void main()
{
clrscr();
add(); Function Call
getch();
}
void add()
{
int a,b,c;
cout <<“Enter two numbers :“ ;
cin >> a >> b; Function Definition =
c = a + b; Function header + Function body
cout <<“Sum = “ << c ;
}
int a = 5; local a = 10
void main() global a = 5
{
int a = 10;
cout << “local a = ” << a ; // local
cout << “global a = ” << :: a ; // global
}