Programming Practices Using C++

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Rabib
R
Rabib
Community Contributor
Quizzes Created: 3 | Total Attempts: 2,305
| Attempts: 682
SettingsSettings
Please wait...
  • 1/70 Questions

     What is object in C++ ?

    • Object is part of syntax of a class.
    • Object is datatype of a class.
    • Object is an instance of a class.
    • Object is function of a class.
Please wait...
Programming Practices Using C++ - Quiz
About This Quiz

Explore key C++ programming concepts through this targeted quiz. Assess your understanding of singleton classes, constructors, inheritance, and more. Enhance your programming skills and prepare for advanced software development roles.


Quiz Preview

  • 2. 

    What is true about Constructor ?

    • Its name is plural of class name.

    • Its name has * symbol before it.

    • Its name is same as of class name.

    • Option 4

    Correct Answer
    A. Its name is same as of class name.
    Explanation
    The correct answer is that the name of a constructor is the same as the name of the class. In object-oriented programming, a constructor is a special method that is used to initialize objects of a class. It is called automatically when an object is created and is responsible for setting initial values for the object's attributes. By convention, the name of the constructor is the same as the name of the class it belongs to. This allows the compiler to identify and call the correct constructor when an object is instantiated.

    Rate this question:

  • 3. 

    Which among following is not a valid visibility mode in c++ program ?

    • Private

    • Public

    • Protected

    • Limited

    Correct Answer
    A. Limited
    Explanation
    The visibility modes in C++ determine the accessibility of class members. Private members can only be accessed within the class, public members can be accessed from anywhere, and protected members can be accessed within the class and its derived classes. However, "Limited" is not a valid visibility mode in C++.

    Rate this question:

  • 4. 

    Which among following is correct way of declaring object of a class ?

    • Classname Objectname;

    • Class Classname Objectname;

    • Class Classname Object Objectname;

    • Classname Object Objectname;

    Correct Answer
    A. Classname Objectname;
    Explanation
    The correct way of declaring an object of a class is by using the syntax "Classname Objectname;". This syntax creates an instance of the class with the specified name. The other options provided in the question are incorrect syntax for declaring objects in C++.

    Rate this question:

  • 5. 

    Which of the following keywords are used to control access to a class member ?

    • Protected

    • Switch

    • Goto

    • For

    Correct Answer
    A. Protected
    Explanation
    The keyword "protected" is used to control access to a class member. It allows the member to be accessed within the class itself, as well as by its subclasses and other classes in the same package. This keyword provides a level of encapsulation and restricts direct access to the member from outside the class hierarchy.

    Rate this question:

  • 6. 

    Data members and member functions are enclosed within ?

    • Union

    • Structure

    • Class

    • Array

    Correct Answer
    A. Class
    Explanation
    In object-oriented programming, data members and member functions are typically enclosed within a class. A class is a blueprint for creating objects that define the properties (data members) and behaviors (member functions) of those objects. It provides a way to organize and encapsulate related data and functions together, allowing for better code organization and reusability.

    Rate this question:

  • 7. 

    Destructor has the same name as the constructor and it is preceded by ______ .

    • !

    • ?

    • ~

    • $

    Correct Answer
    A. ~
    Explanation
    The destructor has the same name as the constructor and is preceded by the tilde (~) symbol. This symbol is used to indicate that the function is a destructor.

    Rate this question:

  • 8. 

    Reference is like a _____. 

    • Structure

    • Pointer

    • Macro

    • Enum

    Correct Answer
    A. Pointer
    Explanation
    A pointer is a reference to a memory address that allows us to directly access and manipulate the data stored at that address. Similarly, a reference in programming is a type that refers to another type, allowing us to access and manipulate the data of the referenced type. Therefore, a pointer can be considered as a reference, making it the most suitable option for completing the analogy in the question.

    Rate this question:

  • 9. 

    Among following which will give the size of object or type ?

    • Calloc

    • Malloc

    • Sizeof

    • Realloc

    Correct Answer
    A. Sizeof
    Explanation
    The sizeof operator in C is used to determine the size, in bytes, of a data type or a variable. It can be used to find the size of built-in data types like int, float, char, etc., as well as user-defined data types such as structures and arrays. Unlike functions like malloc, calloc, and realloc, which are used for dynamic memory allocation, sizeof does not allocate memory. Instead, it simply returns the size of the object or type. Therefore, among the given options, sizeof is the correct choice for finding the size of an object or type.

    Rate this question:

  • 10. 

    What is data hiding ?

    • It is related with hiding internal object details

    • It is related with showing internal object details

    • It is related with datatypes

    • None of above

    Correct Answer
    A. It is related with hiding internal object details
    Explanation
    Data hiding is a concept in object-oriented programming that involves encapsulating the internal details of an object and preventing direct access to them from outside the object. This is done to ensure that the internal state and implementation of an object are not exposed to the external world, promoting security, modularity, and flexibility in software development. By hiding the internal details, the object can control how it is accessed and manipulated, providing a level of abstraction and protecting its integrity.

    Rate this question:

  • 11. 

    What is actual syntax of destructor in c++ ?

    • !Classname( )

    • @Classname( )

    • $Classname( )

    • ~Classname( )

    Correct Answer
    A. ~Classname( )
    Explanation
    The actual syntax of a destructor in C++ is "~Classname( )". The tilde (~) symbol is used to indicate that it is a destructor, followed by the class name in parentheses. The destructor is a special member function that is automatically called when an object of the class is destroyed or goes out of scope. It is used to release any resources or memory that the object may have acquired during its lifetime.

    Rate this question:

  • 12. 

    Which of the following keywords are used to control access to a class member ?

    • Protected

    • Switch

    • Goto

    • For

    Correct Answer
    A. Protected
    Explanation
    The keyword "protected" is used to control access to a class member. It allows the member to be accessed by other members of the same class or by its subclasses. This keyword provides a level of encapsulation and restricts direct access to the member from outside the class hierarchy.

    Rate this question:

  • 13. 

    A reference is declared using the _____ symbol.

    • &&

    • &

    • ||

    • !

    Correct Answer
    A. &
    Explanation
    The correct answer is "&". In programming, the "&" symbol is used to declare a reference variable. A reference variable is a type of variable that refers to an existing object in memory rather than holding its own value. By using the "&" symbol, a reference variable can be declared and assigned to an existing object, allowing multiple variables to refer to the same object.

    Rate this question:

  • 14. 

    Which of following valid option will not return a value in c++ ?

    • Free

    • Void

    • Empty

    • Null

    Correct Answer
    A. Void
    Explanation
    The keyword "void" in C++ is used to indicate that a function does not return a value. It is commonly used for functions that perform actions but do not need to return any specific result. Therefore, the option "void" will not return a value in C++.

    Rate this question:

  • 15. 

    Which of the following is not a type of constructor?

    • Copy constructor

    • Friend constructor

    • Default constructor

    • Parameterized constructor

    Correct Answer
    A. Friend constructor
    Explanation
    A friend constructor is not a type of constructor. In C++, a friend function is a function that is not a member of a class but has access to the private and protected members of the class. However, constructors cannot be declared as friend functions. Therefore, a friend constructor does not exist.

    Rate this question:

  • 16. 

    What is class in c++ ?

    • When you define a class, you define a blueprint for a data type.

    • When you define a class, you make get more funtionality.

    • When you define a class, you define the logic.

    • When you define a class, you make debugging.

    Correct Answer
    A. When you define a class, you define a blueprint for a data type.
    Explanation
    A class in C++ is a blueprint for creating objects of a particular data type. It defines the structure and behavior of the objects that will be created based on the class. By defining a class, you specify the attributes (data members) and methods (member functions) that the objects of that class will have. This allows you to create multiple objects of the same class, each with its own set of attributes and behavior. The class acts as a template or blueprint that can be used to create objects with similar characteristics.

    Rate this question:

  • 17. 

    Which of the following never requires any arguments?

    • Member function

    • Friend function

    • Const function

    • Default constructor

    Correct Answer
    A. Default constructor
    Explanation
    A default constructor is a special type of member function that is automatically called when an object of a class is created without any arguments. It is used to initialize the object's data members to their default values. Unlike other types of functions, a default constructor does not require any arguments to be passed to it. Therefore, it never requires any arguments.

    Rate this question:

  • 18. 

     What is meant by multiple inheritance?

    • Deriving a base class from derived class

    • Deriving a derived class from base class

    • Deriving a derived class from more than one base class

    • None of the mentioned

    Correct Answer
    A. Deriving a derived class from more than one base class
    Explanation
    Multiple inheritance refers to the concept of deriving a derived class from more than one base class. In this scenario, the derived class inherits the properties and behaviors of multiple base classes, allowing it to access and use the features of each base class. This allows for greater flexibility in designing and implementing class hierarchies, as it enables the derived class to combine the characteristics of multiple base classes.

    Rate this question:

  • 19. 

    Which inheritance type is used in the class given below? class A : public X, public Y {}

    • Multilevel inheritance

    • Multiple inheritance

    • Hybrid inheritance

    • Hierarchical Inheritance

    Correct Answer
    A. Multiple inheritance
    Explanation
    The class A is inheriting from two different classes, X and Y, using the public access specifier. This means that class A will have access to both the public and protected members of classes X and Y. This is an example of multiple inheritance, where a class can inherit from multiple base classes.

    Rate this question:

  • 20. 

    & operator is ?

    • Address operator

    • Indirection operator

    • Logical and

    • Logical or

    Correct Answer
    A. Address operator
    Explanation
    The correct answer is "address operator." The & operator in C++ is used as the address operator, which returns the memory address of a variable. It is used to access and manipulate the memory location of a variable, allowing programmers to directly modify the value stored at that memory location.

    Rate this question:

  • 21. 

     How we can define member function outside the class ?

    • Using union

    • Using structure

    • Using pointers

    • Using scope resolution

    Correct Answer
    A. Using scope resolution
    Explanation
    Member functions in C++ can be defined outside the class by using the scope resolution operator (::). This allows the member function to be defined separately from the class declaration, providing better organization and readability of the code. By using the scope resolution operator, the function can be associated with the class and accessed using the class name followed by the scope resolution operator. This method is commonly used when the function implementation is lengthy or when the class has multiple member functions.

    Rate this question:

  • 22. 

    Size of a char is ?

    • 1

    • 2

    • 3

    • 4

    Correct Answer
    A. 1
    Explanation
    The size of a char is 1 byte. In most programming languages, including C and C++, a char data type is used to represent a single character. Since a byte is typically composed of 8 bits, a char can hold 8 bits of information, allowing it to represent a wide range of characters from different character sets.

    Rate this question:

  • 23. 

    When a derived class inherits from many base classes, this process is known as ?

    • Multiple inheritance

    • Multilevel inheritance

    • Default inheritance

    • Multiplex inheritance

    Correct Answer
    A. Multiple inheritance
    Explanation
    Multiple inheritance refers to the process of a derived class inheriting from multiple base classes. In this process, a derived class can inherit the characteristics and behaviors of multiple base classes, allowing for the combination of features from different parent classes. This can be useful in situations where a class needs to inherit from multiple sources to acquire the desired functionality.

    Rate this question:

  • 24. 

    Which of the following type of class allows only one object of it to be created?

    • Virtual class

    • Abstract class

    • Singleton class

    • Friend class

    Correct Answer
    A. Singleton class
    Explanation
    A singleton class allows only one object of it to be created. This is achieved by making the constructor of the class private, so that it cannot be called from outside the class. The class provides a static method that returns the instance of the class, and if an instance already exists, it returns that instance instead of creating a new one. This ensures that only one object of the class can exist at a time, making it a singleton class.

    Rate this question:

  • 25. 

    Which of the following provides a reuse mechanism?

    • Abstraction

    • Inheritance

    • Dynamic binding

    • Encapsulation

    Correct Answer
    A. Inheritance
    Explanation
    Inheritance provides a reuse mechanism in object-oriented programming. It allows a class to inherit properties and behaviors from another class, known as the superclass or base class. This means that the subclass or derived class can reuse and extend the functionality of the superclass, reducing code duplication and promoting code reusability. Inheritance facilitates the creation of a hierarchical relationship between classes, where subclasses can inherit and modify the attributes and methods of the superclass, promoting code organization and modularity.

    Rate this question:

  • 26. 

    Which of the following problem causes an exception?

    • Missing semicolon in statement in main().

    • A problem in calling function.

    • A run-time error.

    • A syntax error.

    Correct Answer
    A. A run-time error.
    Explanation
    A run-time error refers to an error that occurs during the execution of a program. It can be caused by various factors such as dividing by zero, accessing an invalid memory location, or attempting to perform an operation on incompatible data types. In this case, the missing semicolon or a problem in calling a function would result in a syntax error, not a run-time error. Therefore, the correct answer is A run-time error.

    Rate this question:

  • 27. 

    Which among following is used to open a file in binary mode ?

    • Ios:app

    • Ios::out

    • Ios::in

    • Ios::binary

    Correct Answer
    A. Ios::binary
    Explanation
    The correct answer is ios::binary. This is because ios::binary is used to open a file in binary mode. Binary mode is used when dealing with non-text files, such as image or audio files, where the data is represented in binary format instead of characters.

    Rate this question:

  • 28. 

    Which of the following approach is adapted by C++?

    • Top-down

    • Left-right

    • Bottom-up

    • Right-left

    Correct Answer
    A. Bottom-up
    Explanation
    C++ follows the bottom-up approach. This means that the program starts executing from the lowest level of the hierarchy and gradually moves up to the higher levels. In C++, functions are defined before they are used, allowing the program to be organized in a way that functions can call each other in a hierarchical manner. This approach helps in efficient memory management and allows for better code organization and reusability.

    Rate this question:

  • 29. 

    How we can access data members using objects ?

    • Object@datamember

    • Object*datamember

    • Object->datamember

    • Object.datamember

    Correct Answer
    A. Object.datamember
    Explanation
    To access data members using objects, the correct syntax is object.datamember. The dot operator is used to access the data member of an object. This syntax allows us to directly access the data member of the object by specifying the object name followed by a dot and then the data member name.

    Rate this question:

  • 30. 

    Which of the following cannot be passed to a function ?

    • Array

    • Reference variable

    • Object

    • File

    Correct Answer
    A. File
    Explanation
    A file cannot be directly passed to a function because it represents a physical file in the system and is not a data type that can be directly manipulated or passed as a parameter. However, the file can be accessed and manipulated within a function by passing its file path or using file handling functions.

    Rate this question:

  • 31. 

    The major goal of inheritance in C++ is ?

    • To facilitate the reusability of code

    • To help modular programming

    • To facilitate the conversion of data types

    • To extend the capabilities of a class

    Correct Answer
    A. To facilitate the reusability of code
    Explanation
    Inheritance in C++ allows for the reusability of code by allowing a class to inherit the properties and methods of another class. This means that a new class can be created based on an existing class, inheriting its attributes and behaviors. By reusing code in this way, developers can save time and effort by not having to rewrite the same code multiple times. Inheritance also promotes modular programming by allowing classes to be organized into a hierarchical structure, making the code more organized and easier to maintain.

    Rate this question:

  • 32. 

    Which symbol is used to create multiple inheritance? 

    • Dot

    • Comma

    • Dollar

    • None of the mentioned

    Correct Answer
    A. Comma
    Explanation
    Comma is used to create multiple inheritance in some programming languages, such as C++. Multiple inheritance allows a class to inherit from more than one base class, and the comma is used to separate the names of the base classes in the class declaration. This allows the derived class to inherit the properties and behaviors from multiple parent classes.

    Rate this question:

  • 33. 

    Which of the following implicitly creates a default constructor when the programmer does not explicitly define at least one constructor for a class?

    • Linker

    • Preprocessor

    • Compiler

    • Loader

    Correct Answer
    A. Compiler
    Explanation
    The compiler implicitly creates a default constructor when the programmer does not explicitly define at least one constructor for a class. A default constructor is a constructor with no parameters, and it is automatically generated by the compiler if no other constructors are defined. This default constructor initializes the member variables of the class with their default values.

    Rate this question:

  • 34. 

    Pick out the correct statement. 

    • you only need to write one function, and it will work with many different types.

    • it will take a long time to execute

    • Duplicate code is increased

    • None of these

    Correct Answer
    A. you only need to write one function, and it will work with many different types.
    Explanation
    This statement is correct because it suggests that by writing one function, it can be used with multiple types of data. This promotes code reusability and reduces the need for duplicating code for different data types.

    Rate this question:

  • 35. 

    What is purpose of abstract class ?

    • To provide help with database connectivity.

    • To provide data input to other classes.

    • To provide security to other classes.

    • To provide an appropriate base class from which other classes can inherit.

    Correct Answer
    A. To provide an appropriate base class from which other classes can inherit.
    Explanation
    An abstract class is designed to serve as a blueprint or template for other classes to inherit from. It cannot be instantiated on its own but provides a common structure and behavior that can be shared by its subclasses. This allows for code reusability and promotes a hierarchical organization of classes. It also enforces the implementation of certain methods or properties in its subclasses, ensuring that they adhere to a specific contract. Therefore, the purpose of an abstract class is to provide an appropriate base class from which other classes can inherit.

    Rate this question:

  • 36. 

     Which variables cannot be declared ?

    • Structure

    • Pointer

    • Class

    • Void

    Correct Answer
    A. Void
    Explanation
    Void is not a data type and therefore cannot be used to declare variables. Void is typically used as a return type for functions that do not return a value.

    Rate this question:

  • 37. 

    Which of the following operators cannot be overloaded?

    • [ ]

    • ->

    • ?:

    • *

    Correct Answer
    A. ?:
    Explanation
    The ?: operator, also known as the ternary operator, cannot be overloaded. This operator is used for conditional expressions and it takes three operands. It evaluates a condition and returns one of two values depending on whether the condition is true or false. Since the ?: operator is built into the language and has a fixed functionality, it cannot be overloaded to change its behavior.

    Rate this question:

  • 38. 

    Functions can be declared to return a reference type. There are reasons to make such a declaration/Which of the following reasons are correct?
    1. The information being returned is a large enough object that returning a reference is more efficient than returning a copy.
    2. The type of the function must be a R-value.

    • Only 1 is correct.

    • Only 2 is correct.

    • Both 1 and 2 are correct.

    • Both 1 and 2 are incorrect.

    Correct Answer
    A. Both 1 and 2 are correct.
    Explanation
    Both 1 and 2 are correct. Functions can be declared to return a reference type when the information being returned is a large enough object that returning a reference is more efficient than returning a copy. Additionally, the type of the function can be an R-value.

    Rate this question:

  • 39. 

    How many types of polymorphisms are supported by C++?

    • 1

    • 2

    • 3

    • 4

    Correct Answer
    A. 2
    Explanation
    C++ supports two types of polymorphisms: compile-time polymorphism and runtime polymorphism. Compile-time polymorphism is achieved through function overloading and templates, where different functions or templates can be called based on the types of arguments passed. Runtime polymorphism is achieved through inheritance and virtual functions, where a base class pointer can point to objects of different derived classes, and the appropriate function is called based on the actual object type at runtime.

    Rate this question:

  • 40. 

    To ensure that every object in the array receives a destructor call, always delete memory allocated as an array with operator __________ .

    • Delete[ ]

    • Delete

    • Kill[ ]

    • Free[ ]

    Correct Answer
    A. Delete[ ]
    Explanation
    To ensure that every object in the array receives a destructor call, it is necessary to use the "delete[]" operator. This operator is specifically designed to deallocate memory that was allocated using the "new[]" operator for arrays. Using the "delete" operator without the square brackets would only deallocate memory for a single object, not an array of objects. Similarly, "kill[]" and "free[]" are not valid operators in C++ for deallocating memory. Therefore, the correct operator to use in this case is "delete[]".

    Rate this question:

  • 41. 

    What is default visibility mode for members of classes in C++ ?

    • Private

    • Public

    • Protected

    • Depends

    Correct Answer
    A. Private
    Explanation
    In C++, the default visibility mode for members of classes is private. This means that by default, the members of a class are only accessible within the class itself and cannot be accessed from outside the class. Private members can only be accessed through public member functions or friend functions.

    Rate this question:

  • 42. 

    Which one do you like?

    • Option 1

    • Option 2

    • Option 3

    • Option 4

    Correct Answer
    A. Option 1
  • 43. 

    Which of the following ways are legal to access a class data member using this pointer?

    • This->x

    • This.x

    • *this.x

    • *this-x

    Correct Answer
    A. This->x
    Explanation
    The correct way to access a class data member using the this pointer is by using the arrow operator (->). The arrow operator is used to access the member of the object pointed to by the this pointer. In this case, the data member x is accessed using this->x. The other options, this.x, *this.x, and *this-x, are not valid ways to access a class data member using the this pointer.

    Rate this question:

  • 44. 

    Which is correct syntax ?

    • Myfile:open ("example.bin", ios::out);

    • Myfile.open ("example.bin", ios::out);

    • Myfile::open ("example.bin", ios::out);

    • Myfile.open ("example.bin", ios:out);

    Correct Answer
    A. Myfile.open ("example.bin", ios::out);
    Explanation
    The correct syntax is myfile.open ("example.bin", ios::out); because it uses the correct syntax for opening a file with the specified filename and mode. The ios::out flag is used to open the file in output mode, allowing writing to the file.

    Rate this question:

  • 45. 

    Which of the following advantages we lose by using multiple inheritance? 

    • Dynamic binding

    • Polymorphism

    • Both of the above

    • None of these

    Correct Answer
    A. Both of the above
    Explanation
    When using multiple inheritance, we lose the advantage of dynamic binding and polymorphism. Dynamic binding allows the selection of the appropriate function at runtime based on the object type, while polymorphism allows objects of different classes to be treated as objects of a common superclass. However, with multiple inheritance, conflicts may arise when two base classes have the same function name, leading to ambiguity and making it difficult to determine which function should be called. This results in the loss of dynamic binding and polymorphism advantages.

    Rate this question:

  • 46. 

     Which design patterns benefit from the multiple inheritance? 

    • Adapter and observer pattern

    • Code pattern

    • Glue pattern

    • None of the mentioned

    Correct Answer
    A. Adapter and observer pattern
    Explanation
    The adapter and observer patterns benefit from multiple inheritance because they involve the need to inherit from multiple classes or interfaces. The adapter pattern allows objects with incompatible interfaces to work together by adapting one interface to another, and multiple inheritance can be used to inherit from both the target interface and the adapting class. The observer pattern involves a one-to-many relationship between objects, where multiple inheritance can be used to inherit from both the subject being observed and the observer interface. Therefore, these patterns can benefit from multiple inheritance.

    Rate this question:

  • 47. 

    Which is used to describe the function using placeholder types? 

    • Template parameters

    • template type parameters

    • Template type

    • None of the mentioned

    Correct Answer
    A. template type parameters
    Explanation
    Template type parameters are used to describe the function using placeholder types. These parameters allow the function to be flexible and work with different types of data without having to rewrite the function for each specific type. By using template type parameters, the function can be written once and then used with different types as needed.

    Rate this question:

  • 48. 

    Which of the following is an invalid visibility label while inheriting a class?

    • Public

    • Private

    • Protected

    • Friend

    Correct Answer
    A. Friend
    Explanation
    Friend is an invalid visibility label while inheriting a class. In object-oriented programming, friend is not a valid access specifier for inheritance. Public, private, and protected are the three valid access specifiers used to control the visibility of class members in inheritance. Friend is used to grant access to private or protected members of a class to another class or function, but it cannot be used to specify the visibility of a derived class.

    Rate this question:

  • 49. 

    Which one do you like?

    • Option 1

    • Option 2

    • Option 3

    • Option 4

    Correct Answer
    A. Option 1
    Explanation
    The given question asks for personal preference, so the correct answer would depend on the individual's liking. Since the answer provided is "Option 1," it implies that the person prefers the first option among the given choices.

    Rate this question:

Quiz Review Timeline (Updated): Mar 19, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 19, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Aug 14, 2015
    Quiz Created by
    Rabib
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.