Function in c plus

A function in C++ language is a block of code that performs a specific task. It has a name and it is reusable i.e. it can be executed from as many different parts in a C++ Program as required. It also optionally returns a value to the calling program.

Every function has a unique name. This name is used to call function from main() function. A function can be called from within another function.

A function is independent and it can perform its task without intervention from or interfering with other parts of the program.

A function performs a specific task. A task is a distinct job that your program must perform as a part of its overall operation, such as adding two or more integer, sorting an array into numerical order, or calculating a cube root etc.

A function returns a value to the calling program. This is optional and depends upon the task your function is going to accomplish. Suppose you want to just show few lines through function then it is not necessary to return a value. But if you are calculating area of rectangle and wanted to use result somewhere in program then you have to send back (return) value to the calling function.

Structure of Function

FunctionName (Argument1, Argument2, Argument3)

{

Statement1;

Statement2;

Statement3;

}

An example of function.

#include

using namespace std;

int addition (int a, int b)

{

int r;

r=a+b;

return (r);

}

int main ()

{

int z;

z = addition (5,3);

cout 

return 0;

}



You may also like

What is PHP?

PHP stands for PHP: Hypertext pre-processor, with that PHP standi...

What is ASP.NET?

ASP.NET, the next version of ASP, is a programming framework used...

What is Data Structure?

A data structure is a group of data elements grouped together und...

What is C#?

C# removes some of the complexities and pitfalls of languages suc...

What is Math?

Math is no Definition it has only Calculation.Closure Property of...

What is Oracle?

Based in Redwood, California, Oracle Corporation is the largest s...

Function in java

A function in Java language is a block of code that performs a sp...

Do-While Loop in java

The do-while loop looks like this:do{ this ; and this ; and this ...