May 2012
Intermediate to advanced
679 pages
16h 56m
English
So far, we have studied many functions. The arguments (parameters) were basic data types. You may wonder whether an object can be passed as a parameter. Well the answer is yes. Objects can also be parameters to functions (as well as methods). We know that in C++, parameters can be passed by either value or by address (reference). Let us start with style “pass by value”.
Program: Write a program to demonstrate the parameter passing by value. Also check for side effects.
Solution: Let us define a class Point. Let us deliberately keep members as public. Then we will define a function distance. Object of the class Point will be passed as parameter. We will modify one member in the function. ...
Read now
Unlock full access