cpp function exercise

C++ exercise

1. What is an inline function ?

a. A function that is called during compile time
b. A function that is not checked for syntax errors
c. A function that is expanded at each call during execution
d. A function that is not checked for semantic analysis

Show Answer

The correct option is (c)
Explanation:
The Inline function is those which are expanded at each call during the execution of the program to reduce the cost of jumping during execution.

2. An inline function is expanded during ______________

a. run-time
b. never expanded
c. compile-time
d. end of the program

Show Answer

The correct option is (c)
Explanation:
An inline function is expanded during the compile-time of a program.

3. When we define the default values for a function ?

a. When a function is declared.
b. When the scope of the function is over.
c. When a function is defined.
d. When a function is called.

Show Answer

The correct option is (a)
Explanation:
Default values for a function is defined when the function is declared inside a program.

4. From which function the execution of a C++ program starts ?

a. start() function
b. new() function
c. main() function
d. end() function

Show Answer

The correct option is (c)
Explanation:
execution of a C++ program starts with the main() function.

5. Correct way to declare pure virtual function in a C++ class is ?

a. Void virtual foo()= { 0 }
b. Virtual void foo() =0
c. Virtual void foo() {} = 0;
d. None of the above

Show Answer

The correct option is (b)
Explanation:
b is the correct declaration of pure virtual function in a class in C++.NOTE: Pure virtual function is used in an Interface or an abstract class

6. What is the scope of the variable declared in the user defined function ?

a. Only inside the {} block.
b. Whole program.
c. The main function.
d. None of the above.

Show Answer

The correct option is (a)
Explanation:
The variable is valid only in the function block as in other.

7. How many minimum numbers of functions need to be presented in c++?

a. 0
b. 1
c. 2
d. 3

Show Answer

The correct option is (b)
Explanation:
The main function is the mandatory part, it is needed for the execution of the program to start.

8. Unary scope resolution operator is denoted by ?

a. %.
b. &
c. :
d. ::

Show Answer

The correct option is (d)
Explanation:
1 is the minimum numbers of functions need to be presented in c++.

8. Which is more effective while calling the functions ?

a. call by reference
b. call by pointer
c. call by object
d. call by value

Show Answer

The correct option is (a)
Explanation:
In the call by reference, it will just passes the reference of the memory addresses of passed values rather than copying the value to new memories which reduces the overall time and memory use.

  • C++ Dynamic Initialization of Objects
  • C++ Copy Constructor
  • C++ Dynamic Constructor
  • C++ Destructors
  • C++ Exercise
  • C++ Operator Overloading
  • C++ Overloading Unary Operators
  • Const pointer in C
  • Void pointer in c
  • C++ Overloading Binary Operators
  • C++ Overloading Binary Operators Using Friends
  • C++ Manipulation String Using Operators
  • C++ Rules for overloading operators
  • C++ Exercise
  • C++ Basic To class Type
  • C++ Class TO Basic Type
  • C++ One class To another class type
  • C++ Exercise
  • C++ Inheritance introduction
  • C++ Single Inheritance
  • C++ Multiple Inheritance
  • C++ Ambiguity Resolution in inheritance
  • C++ Hierarchical Inheritance
  • C++ Hybrid Inheritance
  • C++ Virtual Base Classes
  • C++ Exercise
  • C++ abstract class
  • C++ nesting of classes
  • C++ Exercise
  • C++ polymorphism
  • C++ Exercise
  • C++ pointers
  • C++ Pointers TO object
  • C++ this pointer
  • C++ Pointer to Derived class
  • C++ Virtual functions
  • C++ Exercise
  • C++ streams
  • C++ unformatted I/O operations
  • C++ Put() and get()
  • C++ getline() and write()
  • C++ Formatted console I/O
  • C++ Manipulators
  • C++ Exercise
  • C++ file handling
  • C++ file stream classes
  • C++ Open and closing file
  • C++ open using constructor
  • C++ open using open()
  • C++ Detecting End of file
  • C++ File modes
  • C++ File pointers and Manipulators
  • C++ Sequential I/O
  • C++ Reading and Writing
  • C++ Updating a File
  • C++ Error handling In File
  • C++ Command Line Arguments
  • C++ Exercise
  • C++ Template introduction
  • C++ Class Templates with multiple Parameters
  • C++ Function templates
  • C++ Function templates with multiple parameters
  • C++ member function Template
  • C++ Exercise
  • C++ Exception handling
  • C++ Basics of Exception Handling
  • C++ Exception Handling Mechanism
  • C++ Throwing Mechanism
  • C++ Catch Mechanism
  • C++ Catch all Exceptions
  • C++ Re-Throwing An Exception
  • C++ Specifying Exceptions
  • C++ Exercise