Experience with Functions
pass the following to the call: int age; double income; char initial
#include <iostream>
using namespace std;
void showDouble(int); //Function prototype
int main()
{
int num;
for (num = 0; num < 10; num++)
showDouble(num);
return 0;
}
// Definition of function showDouble
void showDouble(int value)
{
cout << value << ‘\t’ << (value * 2) << endl;
}
Ans
a) prototype
b) function header
c) prototype
d) function call
e)function call
.
.
showValue(2);
display(age, income, initial);
double output = calPay(2,4.3);
.
.
Output:-
0 0
1 2
2 4
3 6
4 8
5 10
6 12
7 14
8 16
9 18
.//here output ends
prototype have return type written before function name and semicolon at end
function header do not have semicolon at end
function call do not have return type and end with semicolon.
.
function parameters are passed in paranthesis, and return is taken in some variable if not void.
.
the main function has loop that runs from 0 to 10 and call function 10 times. In each call value and its product with 2 is printed separated by tab and line change after print.
.
.
If any doubt ask in the comments.
Please appreciate the work by giving a thumbs up.
.
Get Answers For Free
Most questions answered within 1 hours.