33
|
} |
34
|
void PrintFunction ()
|
35
|
{ |
36
|
// Simply display the following text when called.
//return no value to the caller |
37
|
cout<<"\nWhen PrintFunction is called "<<endl;
|
38
|
cout<<"It returns nothing because it of a void function.
However this message is displayed once it is called"<<endl;
|
39
|
} |
40
|
// When called function DFunction() receives nothing .
// It will however return a value it will calculate basing on its local variables |
41
|
double DFunction()
|
42
|
{ |
43
|
double p = 12.122;
|
44
|
double q=2.0;
|
45
|
cout<<"\nAlthough function DFunction does not receive data when called "
|
46
|
<<"\nIt returns a value"
|
47
|
<<"\nto the calling function..."<<endl;
|
48
|
// return the result to the caller... |
49
|
return p/p;
|
50
|
} |
51
|
int IntFunction(int a,int b)
|
52
|
{ |
53
|
// receive data, works on it and returns the result to the caller |
54
|
a=2;
|
55
|
b = a * 100;
|
56
|
int c=b/4;
|
57
|
cout<<"On completing the calculation function it.. "
|
58
|
<<"\nreturns result to the calling function
which in is this case is main()\n"<<endl;
|
59
|
// now return the data stored in c to main () |
60
|
return c;
|
61
|
} |
62
|
// Function myName receives the names and displays on the screen instead of returning a value |
63
|
void myName(string fname)
|
64
|
{ |
65
|
// receive something but return nothing... |
66
|
string firstName = fname;
|
67
|
cout<<"\nFunction myName receives the name from the caller."<<endl;
|
68
|
cout<<"but does not return any value to the caller, rather..."<<endl;
|
69
| cout<<"Then it processes and displays name as "<<firstName<<endl;
|
70
|
} |
No comments:
Post a Comment