Chapter 4: Review Questions


State whether the following statements are TRUE or FALSE.

  • (a) A function argument is a value returned by the function to the calling program.
  • (b) When arguments are passed by value, the function works with the original arguments in the calling program.
  • (c) When a function returns a value, the entire function call can be assigned to a variable.
  • (d) A function can return a value by reference.
  • (e) When an argument is passed by reference, a temporary variable is created in the calling program to hold the argument value.
  • (f) It is not necessary to specify the variable name in the function prototype.
  • (a) FALSE
  • (b) FALSE
  • (c) TRUE
  • (d) TRUE
  • (e) FALSE
  • (f) TRUE

What are the advantages of function prototypes in C++?


Function prototyping is one of the major improvements added to C++ functions. The prototype describes the function interface to the compiler by giving details such as the number and type of arguments and the type of return values.


Describe the different styles of writing prototypes.


General form of function prototyping :
return_type function_name (argument_list)

Example :
int do_something (void);
float area (float a, float b);
float area (float, float);


Find errors, if any, in the following function prototypes.

  • (a) float average(x,y);
  • (b) int mul(int a,b);
  • (c) int display(….);
  • (d) void Vect(int? &V, int & size);
  • (e) void print(float data[], size = 201);
No. Error Correction
(a) Undefined symbol x, y float average (float x, float y)
(b) Undefined symbol b int mul (int a, int b);
(c) No error
(d) invalid character in variable name void vect (int &v, int &size);
(e) Undefined symbol ‘s’ void print (float data [ ], int size = 20);

What is the main advantage of passing arguments by reference?


When we pass arguments by reference, the formal arguments in the called function become aliases to the ‘actual’ arguments in the calling function.


When will you make a function inline? Why?


When a function contains a small number of statements, then it is declared as inline function. By declaring a function inline the execution time can be minimized.


How does an inline function differ from a preprocessor macro?


The macros are not really functions and therefore, the usual error checking does not occur during compilation. But using inline-function this problem can be solved.


When do we need to use default arguments in a function?


When some constant values are used in a user defined function, then it is needed to assign a default value to the parameter.
Example :


What is the significance of an empty parenthesis in a function declaration?


An empty parentheses implies arguments is void type.


What do you meant by overloading of a function? When do we use this concept?


Overloading of a function means the use of the same thing for different purposes.
When we need to design a family of functions-with one function name but with different argument lists, then we use this concept.


Comment on the following function definitions:

  • (a)
  • (b)

  • (c)
No. comment
(a) This function returns address of m after execution this function.
(b) This function returns 1 after execution.
(c) returns address of n

Next Previous