Q) In C++ code , variables can be passed to a function by
- Pass by value
- Pass by reference
- Pass by pointer
- 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
- void display()
- void display() const
- const void display()
- 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
- I and II
- I only
- I and III
- 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?
- Copy constructor
- Assignment
- Constructor
- 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++
- Static function
- Inline function
- Friend function
- constant function
Answer: 1