Q) In C++ code , variables can be passed to a function by
  1. Pass by value
  2. Pass by reference
  3. Pass by pointer
  4. All the above

Answer: 4
In C++ programming, all pass by value, reference and pointer are used. Note that pass by reference in C Programming language is not available. However, sometimes people use the term pass by reference instead of pass by address or pass by pointers. Read here pass by value and pass by pointer in C programming and what is difference between pass by pointer and pass by reference in C++ language.

Q) Constant function in C++ can be declared as
  1. void display()
  2. void display() const
  3. const void display()
  4. void const display()

Answer: 2

Constant function in a class is used to prevent modification of class member variables inside its body. When we only want to read member variable and use it in function body with no modification then we should use const function. Read detail of constant function in C++ object oriented programming.

Q) True and false statements about inline function in given C++ code example is/are

(I)Static function of a class can be called by class name using scope resolution operator  i.e.  : :
(II)Static function can receive both static and non-static data members of a class
(III)Static function is not the part of an object of a class

  1. I and II
  2. I only
  3. I and III
  4. I, II and III

Answer: 3

Read in detail about static function in c++ with example and if a static function can access non static data in C++ program.

Q) Which of the following functions are provided by compiler by default if we don’t write in a C++ class?
  1. Copy constructor
  2. Assignment
  3. Constructor
  4. All the above

Answer: 4

The all functions are provided by the compiler, if we don’t write in a class. Read more on default functions provided by compiler in C++.

Q) Which function can be called without using an object of a class in C++
  1. Static function
  2. Inline function
  3. Friend function
  4. constant function

Answer: 1

Related Posts