functions
A group of statement that together perform a task
Every c++ program has at least one function which is main.
Function consist of name of function return type and parameters
Void main()
Built-in function also called the library functions
We need not to declare and define these functions because they are already written in c++.
We need to include these functions in program to use
For example #include<iostream> #include<math>
c/c++ allow a programmer to define their own functions
A user defined function groups code to perform a specific task and group of code written by user(programmer)
We need to call the function to use in the program.
program of user define function:
Example 1:
#include<iostream>
using namespace std;
int sum()
{
int a,b;
cout<<"enter value of a "<<endl;
cin>>a;
cout<<"enter value of b "<<endl;
cin>>b;
cout<<"a+b ="<<a+b<<endl;
}
int main()
{
sum();
}
user define function : example 2
#include<iostream>
using namespace std;
int sum(int a,int b)
{
cout<<"a+b ="<<a+b<<endl;
}
int main()
{
sum(10,67);
}
No comments:
Post a Comment