Functions in C++ PDF
Functions in C++ PDF
For instance, you can change the signature, and of course What we are going to do next is writing a program which
the prototype, of the swapValues function in Program gives the value of x for any value entered from the
1.10 as follows. console. C++ has built-in absolute value function, but we
will write our own absolute value function since it is very
easy. The absolute value function which we are going to
define will have a function name of abs. Just to recall
This restricts any change to reference variable a (and
what an absolute value function will do, it gives the value
therefore the original variable a in the main function)
of the number if the number is positive or zero or the
within the function. When you try to run the program you
negative of the number if the number is negative. As the
will get an error message on line 18. Because on that line
negative of a negative number is positive, you will always
you tried to change the value of the reference variable.
have a positive value of a number after passing through
the absolute value function. The program is given below.