Page 288 - Computer_Science_F5
P. 288
Program Example 4.30:
A program to interchange value entered by the user
#include<iostream> Chapter Four: Object oriented programming with C++
using namespace std;
FOR ONLINE READING ONLY
void increment(int &m)
{
m++;
cout<<”The address of m is “<<&m<<endl;
cout<<”m inside the function is “<<m<<endl;
}
int main()
{
int x = 1;
cout<<”The address of x is “<<&x<<endl;
cout<<”Before the call, x is “<<x<<endl;
increment(x); //call by reference
cout<<”After the call, x is “<<x<<endl;
return 0;
}
Output:
Figure 4.59: Output of the program
(iii) Function prototype example of a function prototype is: int
average (int n1, int n2);
Before calling any function into the
main function, it should be defined. This (b) Built-in function
is possible through writing function Built-in functions are functions stored
definition or function prototype. A within standard library files. Such
functions comprise mathematical, string
function prototype is the function header manipulation, conversions, and console-
without function body. The function based I/O function. The application of
body will be given, but the function the built-in function should involve their
should be introduced by writing its header files. For example, <cmath>
prototype. A function prototype contains for the mathematical functions and
<cctype> for character manipulation.
return type, name, and parameters Table 4.15 shows some of the built-in
usually terminated by a semicolon. An function and their application.
279
Student’s Book Form Five
Computer Science Form 5.indd 279 23/07/2024 12:34

