Functions in C++

  1. Which one of the following statements is a valid main function prototype?
    • void main (   );
    • int main (int a, int b)
    • main (int argc, char argv);
    • int main(int argc, char* argv[ ]);
  2. Which one of the following is true about a function in a C++ program?
    • A function must be called at least once.
    • A function may called as and when required.
    • A function can be called only by the main function.
    • A function must always return a value.
  3. Which of the following function prototypes is invalid?
    • void exchange (int, int);
    • void exchange (int a, int b);
    • void exchange (int x, y);
    • void exchange (float, int);
  4. Find the error in the following function prototype double area (int)
    • Argument name is not specified
    • Semicolon at the end is missing
    • Return type and argument type must be same
    • No error
  5. In C++, the main function returns to the operating system
    • an integer value
    • a floating point value
    • address of the function
    • none of the above
  6. The ‘call by reference’ approach of invoking a function enables us to
    • copy the values of arguments into the calling function
    • not to alter the values of the original variables in the calling program
    • change the values of the variables in the calling program
    • use the function on the left-hand side of an assignment statement
  7. Following is a list of function declarations with default values. Which one of them is a valid declaration?
    • float mul(float a=5.0, b=10.0);
    • float mul(int a, float b=10.0, int c);
    • float mul(int a=5, float b);
    • float mul(int a, float b=10.0);
  8. The following is the list of function declarations. Which one of them will be invoked by the function call statement cout <<mul(10.5, 10);
    • int mul(int a, int b);
    • double mul(float a, float b);
    • double mul(int a, double b);
    • int mul(float a, int b);
  9. The usage of macros in C may be replaced in C++ by
    • friend functions
    • inline functions
    • virtual function
    • functions with default arguments
  10. The below function
    • mul(void)
    • {
    • return(5.5 * 3);
    • }
    • when executed will return
    • a) 16
    • b) 16.5
    • c) 16.0
    • d) error
  11. Which of the following statements is true in respect of a function containing const arguments?
    • The function cannot return a value.
    • The function cannot change the value of const arguments.
    • const should be used for the argument passed by reference.
    • const argument cannot be used in any expression.
  12. Which of the following will return the value –8.0 given the value of x to be –8.5?
    • fabs(x)
    • ceil(x)
    • floor(x)
    • all the above

Answers:

  1. int main(int argc, char* argv[ ]);
  2. A function may called as and when required.
  3. void exchange (int x, y);
  4. Semicolon at the end is missing
  5. an integer value
  6. change the values of the variables in the calling program
  7. float mul(int a, float b=10.0);
  8. int mul(float a, int b);
  9. inline functions
  10. error
  11. The function cannot change the value of const arguments.
  12. floor(x)

Related posts