cpp Exercise2

C++ exercise

1. Which of the following is the correct syntax to add the header file in the C++ program?

a. #include “userdefined.h”
b. “userdefined.h”
c. #include < userdefined >
d. Both a and c

Show Answer

The correct option is (d)
Explanation:
To include the herder files in the C++ program user can use any of the following given syntax.
#include “filename.h”
OR
#include

2.Which is the correct syntax to print the message in C++ language?

a. cout <<"Hello world!";
b. Out <<"Hello world!;
c. Cout << Hello world! ;
d. None of the above

Show Answer

The correct option is (a)
Explanation:
For print the message in the C++ language we can use the following syntax
cout << "Hello World!";

3. Which of the following is the address operator? ?

a.@
b.&
c.%
d.#

Show Answer

The correct option is (b)
Explanation:
For print the address of any variable, a user can use the “&” operator. consider the following example:

#include< iostream >
#include< conio.h >
using namespace std;
int main()
{
// Declare Variables
int exam;
int *ptr;
cout << "Print Pointer Address in c++ \n";
exam = 50;
ptr = &exam;
cout << "\n[exam ]:Value of exam = " << exam;
cout << "\n[*ptr]:Value of exam = " << *ptr;
cout << "\n[&exam ]:Address of exam = " << &exam;
cout << "\n[ptr ]:Address of exam= " << ptr;
cout << "\n[&ptr]:Address of ptr = " << &ptr;
cout << "\n[ptr ]:Value of ptr = " << ptr;
getch();
return 0;
}

4. The programming language that has the ability to create new data types is called?

a.Overloaded
b.Encapsulated
c.Extensible
d.Reprehensible

Show Answer

The correct option is (c)
Explanation:
A language that can generate the new data types is known as the extensible languages as they can handle the new data types.

5. In the C++, for what purpose the “rank()” is used?

a. It returns the maximum number of elements that can be stored in the array.
b. It returns the dimension of the specified array.
c. It returns the size of each dimension.
d. None of the above.

Show Answer

The correct option is (b)
Explanation:
In C++, one can use the rank function where he wants to know about the dimensions( e.g., single-dimension, multi-dimension) of a specific array by just passing it to the “rank()” function.

6. Which of the following can be considered as the object of an array?

a. Elements of the Array.
b. Functions of the Array.
c.Elements of the Array
d.All of the above

Show Answer

The correct option is (a)
Explanation:
The elements in the array are known as the objects of the array.

7. Which of the following can be considered as the members that can be inherited but not accessible in any class?

a. Public
b. Protected.
c. Private
d. Both A and C

Show Answer

The correct option is (c)
Explanation:
The “Private” member of a class can be inherited by the child class. Still, the child class cannot access them (Or we can say that they are not accessible from the child class).

8. Which of the following statement is not true about C++ ?

a. Members of a class are public by default.
b. A structure can have the member functions.
c. A class cannot have the private members
d. All of the above

Show Answer

The correct option is (b)
Explanation:
In C, structures are not allowed to have member functions; while on the other hand, C++ allows the structure to have the member functions. Members of the class are generally private by default, and those of the structures are public. So it is a completely false statement that classes can not private members.

8. Which one of the following cannot be used with the virtual keyword ?

a. Destructors
b. Member function
c. Constructor
d. None of the above

Show Answer

The correct option is (c)
Explanation:
In The C++, we cannot use the virtual keyword with the Constructor because constructors are generally defined to initialize the object of a specific class; hence no other class requires the other class’s object.

  • 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