Simple program using function in c++
Function
function refers to a segment that groups code
to perform a specific task.  
A function is a group of statements that together
perform a task. Every C++ program has at least one function, which is main(), and
all the most trivial programs can define additional functions.
A function declaration tell us the compiler about a function's name,
return type, and the parameters. A function definition provides us
the actual body of the any function. 
Now we understand the function through a  program.
We declare a function "add(int , int)".And call the function through the "sum = add(a,b)".in last we give the definition as "add(int x, int y)" .
The progtram is following as....
A function declaration tell us the compiler about a function's name, return type, and the parameters. A function definition provides us the actual body of the any function.
 
 
 
#include <iostream.h>
#include<conio.h>
// Function prototype (declaration)
int add(int, int); 
void  main()
{
    int a,b, sum;
    cout<<"Enters two numbers: ";
    cin >>b >>b;
    // Function call
    sum = add(a,b);
    cout << "Sum is = " << sum;
    getch();
}
// Function definition
int add(int x, int y)
{
    int add;
    add = x + y;
    // Return statement
    return add;
}
 
 
 
 
 
 
OUTPUT
Enters two numbers: 4
4
Sum is :8 
Great post.I appreciate you for sharing this knowledge.This post helps me to improve my knowledge.Iam working in a company namely yiioverlow,which gives the best Angular JS development.
ReplyDeletethank you so much
DeleteI'm dotty for your best article writings and contents auspiciously.
ReplyDeletetutorial on c++
thank you so much
Delete