Functions in C++
Using Functions in C++?
is a set of statements that can be used anywhere in the program. Main reason for using it is to strcuture the programmming by creating function for repetitive tasks.
return-type function-name(parameter list)
In the above syntax the "return-type" defines the data type of the value returned by the functions, the "function-name", unique name used to call a function. The "Parameters" are seperated by commas that consist of the data type along with identfiers for the parameters.
addition(int a, int b)
r = a + b;
cout << "Enter the first integer::"; cin >> x;
cout << "Enter the second integer::"; cin >> y;
z = addition(x,y);
cout << "Sum of X and Y is::" << z << '\n';
Enter the first integer::10
Enter the second integer::20
Sum of X and Y is:: 30
In the above example a function "addition()" is used to add two numbers.