Breaking

Sunday, March 30, 2025

BCA 2nd Sem -Object Oriented Programming Using C++ UNIT-1 MCQ

 


BCA 2nd Sem -Object Oriented Programming Using C++ UNIT-1 MCQ


  • UNIT-I 
   -Introducing Object  Oriented Approach                -Relating to other paradigms {Functional, Data decomposition}                         - Basic terms and ideas Abstraction, Encapsulation, Inheritance, Polymorphism  - - Review of C                            -Difference between C and C++ - cin, cout, new, delete, operators
   .
 Unit-1 MCQ's
  • UNIT-II 
  • - Classes and Objects Encapsulation                                   -information hiding,                 - abstract data types,                  -Object & classes                   -attributes                                       -methods                                -C++ class declaration               -State idendity and behaviour of an object                                  -Constructors and destructors,                                -instantiation of objects,            -Default parameter value,         -object types,                             -C++ garbage collection,        -dynamic memory allocation,                -abstract classes.
    Unit-2 MCQ's
  • UNIT-III 
  •  - Inheritance and Polymorphism Inheritance,     -Class hierarchy,                     -derivation – public, private & protected,                              -Aggregation,                            - composition vs classification hierarchies,                               -Polymorphism,                       -Categorization of polymorphism techniques,      -Method polymorphism,         - Operator overloading                 
    Unit-3 MCQ's
  • UNIT-IV 
  • -Generic function Template function,                                    -function name overloading,    -Overriding inheritance methods,                                    -Run time polymorphism,       -Multiple Inheritance

  • UNIT-V                 
  • - Files and Exception Handling Streams and files,                                                                 - Exception handling

    Unit-5 MCQ's

    Object Oriented Programming Using C++ 


    1. Which of the following is NOT a fundamental concept of OOP?
      a) Encapsulation
      b) Abstraction
      c) Recursion
      d) Inheritance
      Answer: c) Recursion

    2. An object is an instance of a:
      a) Function
      b) Class
      c) Structure
      d) Method
      Answer: b) Class

    3. The process of binding data and functions together is known as:
      a) Encapsulation
      b) Abstraction
      c) Polymorphism
      d) Inheritance
      Answer: a) Encapsulation

    4. Which OOP concept ensures only relevant details are exposed?
      a) Encapsulation
      b) Abstraction
      c) Inheritance
      d) Polymorphism
      Answer: b) Abstraction

    5. Which of the following features allow a function to take multiple forms?
      a) Abstraction
      b) Polymorphism
      c) Encapsulation
      d) Inheritance
      Answer: b) Polymorphism


    Section 2: Comparison with Other Paradigms

    1. Which paradigm emphasizes the evaluation of mathematical functions?
      a) Object-Oriented
      b) Functional Programming
      c) Procedural Programming
      d) Data Decomposition
      Answer: b) Functional Programming

    2. What is the primary focus of the functional programming paradigm?
      a) Objects and Classes
      b) Functions as first-class citizens
      c) Data Structures
      d) Sequential Execution
      Answer: b) Functions as first-class citizens

    3. Functional programming avoids:
      a) Recursion
      b) Immutability
      c) Side effects
      d) Higher-order functions
      Answer: c) Side effects

    4. Which of the following languages is considered a functional programming language?
      a) C++
      b) Python
      c) Lisp
      d) Java
      Answer: c) Lisp

    5. Which paradigm focuses on breaking down data into smaller chunks for processing?
      a) Object-Oriented
      b) Functional Programming
      c) Data Decomposition
      d) Procedural Programming
      Answer: c) Data Decomposition


    Section 3: Functional vs Object-Oriented Programming

    1. Functional programming is mostly:
      a) Immutable
      b) Mutable
      c) Both immutable and mutable
      d) State-dependent
      Answer: a) Immutable

    2. Object-oriented programming relies on:
      a) Mutable state
      b) First-class functions
      c) Side-effect-free functions
      d) Recursion
      Answer: a) Mutable state

    3. Which approach follows the principle of "functions as first-class citizens"?
      a) Functional Programming
      b) Object-Oriented Programming
      c) Procedural Programming
      d) Data Decomposition
      Answer: a) Functional Programming

    4. A key advantage of functional programming over object-oriented programming is:
      a) Better readability
      b) More state management
      c) Higher mutability
      d) Increased code size
      Answer: a) Better readability

    5. In functional programming, data is treated as:
      a) Mutable
      b) Immutable
      c) Dynamic
      d) Static
      Answer: b) Immutable


    Section 4: Object-Oriented Programming Concepts

    1. The process of reusing existing classes is called:
      a) Encapsulation
      b) Abstraction
      c) Inheritance
      d) Polymorphism
      Answer: c) Inheritance

    2. The concept of defining multiple functions with the same name but different arguments is called:
      a) Function Overriding
      b) Function Overloading
      c) Encapsulation
      d) Data Hiding
      Answer: b) Function Overloading

    3. What is an advantage of OOP over procedural programming?
      a) Easy to modify
      b) Reduces code reusability
      c) Increases code complexity
      d) No real advantage
      Answer: a) Easy to modify

    4. Which of the following best describes a class in OOP?
      a) A blueprint for creating objects
      b) A specific instance of an object
      c) A function
      d) A primitive data type
      Answer: a) A blueprint for creating objects

    5. Which of the following is NOT an access specifier in OOP?
      a) Public
      b) Private
      c) Internal
      d) Protected
      Answer: c) Internal


    Section 5: Data Decomposition Approach

    1. Data decomposition is commonly used in:
      a) Parallel Computing
      b) Object-Oriented Programming
      c) Functional Programming
      d) Logical Programming
      Answer: a) Parallel Computing

    2. A key advantage of data decomposition is:
      a) Reduced code reusability
      b) Better parallel execution
      c) Increased memory usage
      d) Poor modularity
      Answer: b) Better parallel execution

    3. In which scenario is data decomposition most useful?
      a) Small-scale applications
      b) Large datasets with parallel processing needs
      c) Single-threaded applications
      d) Programs with no data-sharing
      Answer: b) Large datasets with parallel processing needs

    4. The primary goal of data decomposition is to:
      a) Break down logic into smaller components
      b) Split data for independent processing
      c) Implement object-oriented principles
      d) Increase memory usage
      Answer: b) Split data for independent processing

    5. Which paradigm is closest to data decomposition?
      a) Object-Oriented Programming
      b) Functional Programming
      c) Parallel Computing
      d) Logical Programming
      Answer: c) Parallel Computing


    Section 6: Mixed MCQs

    1. Which of these programming paradigms encourages reusability the most?
      a) OOP
      b) Functional Programming
      c) Data Decomposition
      d) Assembly Language
      Answer: a) OOP

    2. Which paradigm avoids mutable state as much as possible?
      a) Object-Oriented Programming
      b) Functional Programming
      c) Procedural Programming
      d) Data Decomposition
      Answer: b) Functional Programming

    3. Encapsulation helps in:
      a) Code maintainability
      b) Increasing redundancy
      c) Making code complex
      d) Decreasing security
      Answer: a) Code maintainability

    4. Which OOP principle allows a subclass to provide a specific implementation of a method in the parent class?
      a) Abstraction
      b) Encapsulation
      c) Polymorphism
      d) Inheritance
      Answer: c) Polymorphism

    5. What is the main advantage of object-oriented programming?
      a) Increased modularity
      b) Complex implementation
      c) High memory usage
      d) No practical benefit
      Answer: a) Increased modularity

    31. What is encapsulation in OOP?

    a) The ability to take multiple forms
    b) The process of binding data and methods together
    c) The process of inheriting from another class
    d) The ability to hide a class definition
    Answer: b) The process of binding data and methods together


    32. What is the primary purpose of encapsulation?

    a) To allow direct access to object data
    b) To protect data from unauthorized access
    c) To slow down execution
    d) To remove abstraction
    Answer: b) To protect data from unauthorized access


    33. Encapsulation helps in:

    a) Data hiding
    b) Code execution
    c) Increasing program size
    d) Making all variables public
    Answer: a) Data hiding


    34. How is encapsulation implemented in Java?

    a) Using private variables and public getter and setter methods
    b) Using global variables
    c) By making all methods public
    d) By avoiding methods in a class
    Answer: a) Using private variables and public getter and setter methods


    35. Which access modifier restricts access to a class member within the same class only?

    a) public
    b) protected
    c) private
    d) default
    Answer: c) private


    36. In Java, how can a private variable be accessed outside the class?

    a) Using global keyword
    b) Using getter and setter methods
    c) By making it public
    d) By using a friend function
    Answer: b) Using getter and setter methods


    37. What will happen if a class has only private variables?

    a) It will not compile
    b) The variables cannot be accessed outside the class
    c) It will cause a runtime error
    d) The variables can be accessed directly
    Answer: b) The variables cannot be accessed outside the class


    38. In C++, which access specifier is used to achieve encapsulation?

    a) private
    b) protected
    c) public
    d) All of the above
    Answer: d) All of the above


    39. Which of the following is NOT an advantage of encapsulation?

    a) Increases security
    b) Prevents direct modification of data
    c) Makes code less reusable
    d) Helps in maintaining code easily
    Answer: c) Makes code less reusable


    40. Encapsulation is also known as:

    a) Data hiding
    b) Code reusability
    c) Polymorphism
    d) Multiple inheritance
    Answer: a) Data hiding


    41. Which of the following statements is TRUE about encapsulation?

    a) It allows modification of private members directly
    b) It helps in hiding implementation details
    c) It does not help in data security
    d) It makes all class members public
    Answer: b) It helps in hiding implementation details


    42. What is the default access modifier for class members in Java?

    a) public
    b) private
    c) protected
    d) default (package-private)
    Answer: d) default (package-private)


    43. In C++, encapsulation is achieved using:

    a) Classes
    b) Functions
    c) Arrays
    d) Macros
    Answer: a) Classes


    44. What will happen if we do not use encapsulation in OOP?

    a) Data security may be compromised
    b) Code will run faster
    c) Classes will execute automatically
    d) Methods cannot be defined in a class
    Answer: a) Data security may be compromised


    45. Which of the following statements about encapsulation is FALSE?

    a) Encapsulation increases security by hiding data
    b) Encapsulation allows direct access to private data members
    c) Encapsulation makes code more modular and maintainable
    d) Encapsulation is implemented using access modifiers
    Answer: b) Encapsulation allows direct access to private data members


    46. What is inheritance in OOP?

    a) A way to hide data from unauthorized access
    b) A feature that allows a class to acquire properties and behavior of another class
    c) A way to achieve multiple method definitions
    d) A way to implement polymorphism
    Answer: b) A feature that allows a class to acquire properties and behavior of another class


    47. Which keyword is used to inherit a class in Java?

    a) implements
    b) extends
    c) inherits
    d) super
    Answer: b) extends


    48. In C++, which access specifier allows a derived class to access public and protected members of a base class?

    a) public
    b) private
    c) protected
    d) static
    Answer: a) public


    49. What is the base class also known as?

    a) Superclass
    b) Subclass
    c) Parent interface
    d) Object class
    Answer: a) Superclass


    50. What is the derived class also known as?

    a) Subclass
    b) Superclass
    c) Base class
    d) Interface
    Answer: a) Subclass


    51. Which type of inheritance is not supported in Java?

    a) Single inheritance
    b) Multilevel inheritance
    c) Multiple inheritance
    d) Hierarchical inheritance
    Answer: c) Multiple inheritance (Java supports it through interfaces but not through classes)


    52. What is multilevel inheritance?

    a) A class is derived from more than one base class
    b) A derived class becomes a base class for another class
    c) All classes in a program inherit from a single base class
    d) A class has multiple constructors
    Answer: b) A derived class becomes a base class for another class


    53. What is hierarchical inheritance?

    a) A single class inherits from multiple classes
    b) Multiple classes inherit from a single base class
    c) A class is inherited in a multilevel structure
    d) A class can have only one parent class
    Answer: b) Multiple classes inherit from a single base class


    54. Which of the following is a benefit of inheritance?

    a) Increases code redundancy
    b) Improves code reusability
    c) Makes debugging harder
    d) Increases complexity unnecessarily
    Answer: b) Improves code reusability


    55. How can a subclass call the constructor of its parent class in Java?

    a) Using this()
    b) Using super()
    c) Using base()
    d) Calling the constructor directly
    Answer: b) Using super()


    56. Which of the following statements about inheritance is FALSE?

    a) Inheritance promotes code reuse
    b) Inheritance supports hierarchical classification
    c) Private members of the base class are directly accessible in the derived class
    d) A derived class can override a base class method
    Answer: c) Private members of the base class are directly accessible in the derived class


    57. In C++, which type of inheritance is shown in the syntax below?

    class B : public A { };

    a) Private inheritance
    b) Public inheritance
    c) Protected inheritance
    d) Multilevel inheritance
    Answer: b) Public inheritance


    58. In Java, if a class does not explicitly extend another class, which class does it inherit from by default?

    a) Object
    b) SuperClass
    c) BaseClass
    d) None
    Answer: a) Object


    59. What happens when a derived class defines a method with the same name as a method in the base class?

    a) The base class method gets executed
    b) The derived class method overrides the base class method
    c) A syntax error occurs
    d) Both methods execute simultaneously
    Answer: b) The derived class method overrides the base class method


    60. Which of the following access modifiers allow a member of a base class to be inherited but not directly accessed by objects of the derived class?

    a) private
    b) protected
    c) public
    d) default
    Answer: b) protected


    61. What is polymorphism in OOP?

    a) The ability of different classes to be inherited from a base class
    b) The ability to take multiple forms
    c) The ability to encapsulate data
    d) The ability to create objects
    Answer: b) The ability to take multiple forms


    62. Which of the following is an example of polymorphism?

    a) Function overloading
    b) Function overriding
    c) Operator overloading
    d) All of the above
    Answer: d) All of the above


    63. What are the two types of polymorphism?

    a) Static and dynamic polymorphism
    b) Private and public polymorphism
    c) Single and multiple polymorphism
    d) Encapsulation and abstraction
    Answer: a) Static and dynamic polymorphism


    64. Function overloading is an example of:

    a) Static polymorphism
    b) Dynamic polymorphism
    c) Multiple inheritance
    d) Data hiding
    Answer: a) Static polymorphism


    65. Function overriding is an example of:

    a) Static polymorphism
    b) Dynamic polymorphism
    c) Encapsulation
    d) Multiple inheritance
    Answer: b) Dynamic polymorphism


    66. What is method overloading?

    a) Defining multiple methods with the same name but different parameters
    b) Replacing an inherited method with a new definition
    c) Using multiple classes with the same method names
    d) Using private methods in a class
    Answer: a) Defining multiple methods with the same name but different parameters


    67. What is method overriding?

    a) Defining multiple functions with the same name in a single class
    b) Redefining a function in a subclass that already exists in the parent class
    c) Using multiple constructors in a class
    d) Defining a private method in a derived class
    Answer: b) Redefining a function in a subclass that already exists in the parent class


    68. In Java, which keyword is used to override a method?

    a) override
    b) extends
    c) implements
    d) No keyword is required
    Answer: d) No keyword is required (but @Override annotation is recommended)


    69. Which concept allows one interface to be used for a general class of actions?

    a) Abstraction
    b) Encapsulation
    c) Polymorphism
    d) Inheritance
    Answer: c) Polymorphism


    70. What is operator overloading?

    a) Assigning multiple meanings to an operator
    b) Using multiple classes to override a method
    c) Overriding a base class method in a derived class
    d) Using multiple interfaces in a class
    Answer: a) Assigning multiple meanings to an operator


    71. In C++, which operator cannot be overloaded?

    a) +
    b) =
    c) ::
    d) ==
    Answer: c) :: (Scope resolution operator)


    72. What happens if a subclass method has the same signature as a superclass method?

    a) It causes an error
    b) The subclass method overrides the superclass method
    c) Both methods are executed
    d) The superclass method is always called
    Answer: b) The subclass method overrides the superclass method


    73. Which method is used for achieving runtime polymorphism in Java?

    a) Method overloading
    b) Method overriding
    c) Operator overloading
    d) Constructor overloading
    Answer: b) Method overriding


    74. What is the main advantage of polymorphism?

    a) Improves code readability and reusability
    b) Increases execution time
    c) Prevents method overriding
    d) Makes code more complex
    Answer: a) Improves code readability and reusability


    75. Which of the following statements is TRUE about polymorphism?

    a) It reduces flexibility in programming
    b) It allows the same function to be used for different types
    c) It does not allow dynamic method binding
    d) It prevents code reusability
    Answer: b) It allows the same function to be used for different types


    76. What is the main purpose of abstraction in OOP?

    a) To hide implementation details and show only essential features
    b) To increase code complexity
    c) To improve execution speed
    d) To make all data public
    Answer: a) To hide implementation details and show only essential features


    77. How is abstraction implemented in Java?

    a) Using abstract classes and interfaces
    b) Using constructors
    c) Using friend functions
    d) Using global variables
    Answer: a) Using abstract classes and interfaces


    78. Which OOP principle helps in reducing code complexity by exposing only necessary details?

    a) Inheritance
    b) Encapsulation
    c) Abstraction
    d) Polymorphism
    Answer: c) Abstraction


    79. In Java, an abstract class can have:

    a) Only abstract methods
    b) Only concrete methods
    c) Both abstract and concrete methods
    d) Only private variables
    Answer: c) Both abstract and concrete methods


    80. What is the correct syntax for defining an abstract method in Java?

    a) public void abstract methodName();
    b) abstract void methodName();
    c) void methodName() abstract;
    d) abstract: void methodName();
    Answer: b) abstract void methodName();


    81. Which of the following statements about abstraction is FALSE?

    a) Abstraction focuses on what an object does rather than how it does it
    b) Abstract classes can be instantiated
    c) Abstract classes can have constructors
    d) Interfaces provide full abstraction
    Answer: b) Abstract classes can be instantiated


    82. In C++, abstraction can be achieved using:

    a) Abstract classes and pure virtual functions
    b) Only friend functions
    c) Only templates
    d) Only global variables
    Answer: a) Abstract classes and pure virtual functions


    83. Which keyword is used to define an abstract class in C++?

    a) abstract
    b) virtual
    c) class
    d) There is no specific keyword
    Answer: d) There is no specific keyword (but abstract behavior is achieved using pure virtual functions)


    84. What happens if a class contains at least one pure virtual function in C++?

    a) The class becomes an abstract class
    b) The class can be instantiated
    c) The class cannot have constructors
    d) The class must not have member variables
    Answer: a) The class becomes an abstract class


    85. Which of the following best defines an abstract method?

    a) A method with no body, only a declaration
    b) A method with an implementation
    c) A method that cannot be overridden
    d) A method that must be private
    Answer: a) A method with no body, only a declaration


    86. Can an abstract class have a constructor in Java?

    a) Yes
    b) No
    Answer: a) Yes


    87. Which of the following provides full abstraction in Java?

    a) Abstract class
    b) Interface
    c) Concrete class
    d) Static class
    Answer: b) Interface


    88. What will happen if a class does not implement all methods of an interface?

    a) Compilation error
    b) Runtime error
    c) The program executes normally
    d) The missing methods are automatically added
    Answer: a) Compilation error


    89. Why is abstraction important in software development?

    a) It helps in hiding unnecessary implementation details
    b) It increases execution time
    c) It makes code harder to maintain
    d) It forces all data to be public
    Answer: a) It helps in hiding unnecessary implementation details


    90. Can an abstract class have final methods in Java?

    a) Yes
    b) No
    Answer: a) Yes

    91. Who is the father of the C programming language?

    a) Bjarne Stroustrup
    b) Dennis Ritchie
    c) James Gosling
    d) Ken Thompson
    Answer: b) Dennis Ritchie


    92. What is the main purpose of the #include <stdio.h> directive in C?

    a) To define macros
    b) To include standard input-output library functions
    c) To link external files
    d) To compile the code
    Answer: b) To include standard input-output library functions


    93. What is the correct syntax to declare a variable in C?

    a) int x;
    b) x int;
    c) integer x;
    d) declare int x;
    Answer: a) int x;


    94. Which of the following is used to read a string from user input in C?

    a) printf()
    b) scanf()
    c) cout >>
    d) input()
    Answer: b) scanf()


    95. What is the output of printf("%d", 5+2);?

    a) 5
    b) 2
    c) 7
    d) Error
    Answer: c) 7


    96. What is the default return type of a function in C if not specified?

    a) void
    b) int
    c) float
    d) char
    Answer: b) int


    97. Which of the following data types stores only a single character in C?

    a) int
    b) char
    c) float
    d) double
    Answer: b) char


    98. What will be the output of printf("%d", 10/3); in C?

    a) 3.33
    b) 3
    c) 10/3
    d) Error
    Answer: b) 3


    99. What is the size of int data type in most modern C compilers (assuming 32-bit system)?

    a) 1 byte
    b) 2 bytes
    c) 4 bytes
    d) 8 bytes
    Answer: c) 4 bytes


    100. Which symbol is used for single-line comments in C?

    a) //
    b) /* */
    c) #
    d) --
    Answer: a) //


    101. Which loop is guaranteed to execute at least once in C?

    a) for loop
    b) while loop
    c) do-while loop
    d) None of the above
    Answer: c) do-while loop


    102. What is the purpose of the return statement in C?

    a) To terminate a program
    b) To return a value from a function
    c) To skip an iteration in a loop
    d) To print output
    Answer: b) To return a value from a function


    103. What is the correct syntax to declare an array in C?

    a) array[10] int;
    b) int array[10];
    c) int[10] array;
    d) array int[10];
    Answer: b) int array[10];


    104. How do you access the first element of an array in C?

    a) array[0]
    b) array[1]
    c) array.first()
    d) array{0}
    Answer: a) array[0]


    105. What will happen if you try to access an array element beyond its size in C?

    a) Compilation error
    b) Runtime error
    c) Unexpected behavior (undefined behavior)
    d) Program will exit successfully
    Answer: c) Unexpected behavior (undefined behavior)


    106. Which of the following correctly declares a pointer in C?

    a) int ptr;
    b) int *ptr;
    c) int &ptr;
    d) pointer int ptr;
    Answer: b) int *ptr;


    107. What is the output of the following C code?


    int x = 5; printf("%d", x++);

    a) 4
    b) 5
    c) 6
    d) Error
    Answer: b) 5 (Post-increment returns the value before incrementing)


    108. What is the correct way to dynamically allocate memory for an integer in C?

    a) int *ptr = malloc(sizeof(int));
    b) int ptr = malloc(int);
    c) int *ptr = int malloc();
    d) malloc int;
    Answer: a) int *ptr = malloc(sizeof(int));


    109. What is the purpose of the free() function in C?

    a) Allocates memory
    b) Releases dynamically allocated memory
    c) Returns a pointer
    d) Declares a pointer
    Answer: b) Releases dynamically allocated memory


    110. Which library should be included to use malloc() and free() functions in C?

    a) <stdlib.h>
    b) <stdio.h>
    c) <string.h>
    d) <math.h>
    Answer: a) <stdlib.h>

    111. Which programming paradigm does C follow?

    a) Object-Oriented Programming (OOP)
    b) Procedural Programming
    c) Functional Programming
    d) Logic Programming
    Answer: b) Procedural Programming


    112. C++ is an extension of which programming language?

    a) Java
    b) Python
    c) C
    d) Ruby
    Answer: c) C


    113. Which of the following features is NOT available in C but is available in C++?

    a) Functions
    b) Pointers
    c) Classes and Objects
    d) Loops
    Answer: c) Classes and Objects


    114. What is the main programming paradigm of C++?

    a) Only procedural
    b) Only object-oriented
    c) Both procedural and object-oriented
    d) Assembly language
    Answer: c) Both procedural and object-oriented


    115. In C++, which feature allows data and functions to be bundled together?

    a) Abstraction
    b) Encapsulation
    c) Inheritance
    d) Compilation
    Answer: b) Encapsulation


    116. Which keyword is used to define a class in C++?

    a) struct
    b) class
    c) object
    d) define
    Answer: b) class


    117. How are functions defined in C++ that belong to a class?

    a) Using the function keyword
    b) Using the method keyword
    c) By defining them inside a class
    d) By defining them outside a class
    Answer: c) By defining them inside a class


    118. Which of the following is NOT supported by C but is supported by C++?

    a) Pointer Arithmetic
    b) Dynamic Memory Allocation
    c) Function Overloading
    d) File Handling
    Answer: c) Function Overloading


    119. What is the standard input/output library in C?

    a) <iostream>
    b) <stdio.h>
    c) <string.h>
    d) <stdlib.h>
    Answer: b) <stdio.h>


    120. What is the standard input/output library in C++?

    a) <stdio.h>
    b) <iostream>
    c) <string.h>
    d) <stdlib.h>
    Answer: b) <iostream>


    121. How does C handle input and output?

    a) Using cin and cout
    b) Using printf and scanf
    c) Using read and write
    d) Using system.out.println
    Answer: b) Using printf and scanf


    122. How does C++ handle input and output?

    a) Using printf and scanf
    b) Using cin and cout
    c) Using System.out.println
    d) Using print and input
    Answer: b) Using cin and cout


    123. Which of the following is an OOP feature present in C++ but NOT in C?

    a) Arrays
    b) Pointers
    c) Inheritance
    d) Switch-case statements
    Answer: c) Inheritance


    124. Which of the following is NOT an OOP concept in C++?

    a) Encapsulation
    b) Polymorphism
    c) Abstraction
    d) Structured Programming
    Answer: d) Structured Programming


    125. How does C++ handle memory allocation?

    a) Using malloc() and free()
    b) Using new and delete
    c) Using create and destroy
    d) Using allocate and release
    Answer: b) Using new and delete


    126. How does C handle memory allocation?

    a) Using new and delete
    b) Using malloc() and free()
    c) Using allocate and release
    d) Using assign and remove
    Answer: b) Using malloc() and free()


    127. Which of the following does NOT exist in C?

    a) Pointers
    b) Constructors and Destructors
    c) Arrays
    d) Loops
    Answer: b) Constructors and Destructors


    128. Which of the following statements is true about C++?

    a) It does not support object-oriented programming
    b) It is a completely new language unrelated to C
    c) It supports both procedural and object-oriented programming
    d) It does not support function overloading
    Answer: c) It supports both procedural and object-oriented programming


    129. What is the default access modifier for class members in C++?

    a) private
    b) public
    c) protected
    d) default
    Answer: a) private


    130. Which of the following is a major advantage of using C++ over C?

    a) Faster execution
    b) Easier debugging
    c) Object-oriented programming features
    d) Less memory consumption
    Answer: c) Object-oriented programming features

    131. What is cin used for in C++?

    a) Output operation
    b) Input operation
    c) File handling
    d) Memory allocation
    Answer: b) Input operation


    132. What is cout used for in C++?

    a) Output operation
    b) Input operation
    c) Memory allocation
    d) File handling
    Answer: a) Output operation


    133. Which header file is required to use cin and cout?

    a) <stdio.h>
    b) <iostream>
    c) <fstream>
    d) <stdlib.h>
    Answer: b) <iostream>


    134. What operator is used with cin for input?

    a) >>
    b) <<
    c) =
    d) ::
    Answer: a) >>


    135. What operator is used with cout for output?

    a) <<
    b) >>
    c) ==
    d) ::
    Answer: a) <<


    136. Which of the following is correct syntax for cin?

    a) cin << x;
    b) cin >> x;
    c) cin = x;
    d) cin.input(x);
    Answer: b) cin >> x;


    137. What will happen if cin fails to read input correctly?

    a) The program crashes
    b) The program exits automatically
    c) cin goes into an error state
    d) The input is automatically corrected
    Answer: c) cin goes into an error state


    138. What function clears the error state of cin?

    a) cin.clear()
    b) cin.reset()
    c) cin.ignore()
    d) cin.flush()
    Answer: a) cin.clear()


    139. What function is used to ignore unwanted input in cin?

    a) cin.ignore()
    b) cin.clear()
    c) cin.flush()
    d) cin.reset()
    Answer: a) cin.ignore()


    140. How do you output a newline using cout?

    a) cout.newline;
    b) cout << endl;
    c) cout.new();
    d) cout << "\end";
    Answer: b) cout << endl;


    new and delete (141-150)

    141. What is the purpose of the new operator in C++?

    a) To declare a variable
    b) To allocate memory dynamically
    c) To free memory
    d) To initialize a pointer
    Answer: b) To allocate memory dynamically


    142. Which operator is used to free dynamically allocated memory?

    a) free
    b) delete
    c) clear
    d) dispose
    Answer: b) delete


    143. What is the correct syntax to allocate memory for an integer using new?

    a) int *ptr = new int;
    b) int *ptr = malloc(sizeof(int));
    c) int ptr = new int;
    d) int ptr = malloc(int);
    Answer: a) int *ptr = new int;


    144. How do you properly free memory allocated using new?

    a) delete ptr;
    b) free(ptr);
    c) delete *ptr;
    d) ptr.delete();
    Answer: a) delete ptr;


    145. How do you allocate memory for an array using new?

    a) int *arr = new int[10];
    b) int *arr = new[10] int;
    c) int arr = new int(10);
    d) new int arr[10];
    Answer: a) int *arr = new int[10];


    146. What is the correct way to deallocate memory of an array allocated using new?

    a) delete arr;
    b) delete[] arr;
    c) free(arr);
    d) delete arr[];
    Answer: b) delete[] arr;


    147. What happens if you forget to use delete after using new?

    a) Memory leak
    b) Compilation error
    c) Segmentation fault
    d) Automatic deallocation
    Answer: a) Memory leak


    148. What does delete ptr; do if ptr is already NULL?

    a) Causes an error
    b) Deletes the NULL pointer
    c) Does nothing
    d) Crashes the program
    Answer: c) Does nothing


    149. Which statement is true about new and malloc()?

    a) new is faster than malloc()
    b) malloc() calls the constructor of an object
    c) new returns void*
    d) malloc() and new are identical
    Answer: a) new is faster than malloc()


    150. What is the difference between delete and delete[]?

    a) delete is for single objects, delete[] is for arrays
    b) delete[] is used for pointers only
    c) delete is used only in C
    d) delete[] is slower than delete
    Answer: a) delete is for single objects, delete[] is for arrays


    Operators (151-160)

    151. Which operator is used for pointer dereferencing?

    a) &
    b) *
    c) ->
    d) .
    Answer: b) *


    152. Which operator cannot be overloaded?

    a) +
    b) =
    c) ::
    d) []
    Answer: c) ::


    153. What is the result of 5 / 2 in C++ (assuming integer division)?

    a) 2.5
    b) 2
    c) 3
    d) Compilation error
    Answer: b) 2


    154. What is the modulus operator (%) used for?

    a) Division
    b) Remainder calculation
    c) Multiplication
    d) Exponentiation
    Answer: b) Remainder calculation


    155. Which of the following is a ternary operator?

    a) &&
    b) ?:
    c) ++
    d) --
    Answer: b) ?:


    156. What is the sizeof operator used for?

    a) Finding variable values
    b) Allocating memory
    c) Finding the size of a data type
    d) Deleting objects
    Answer: c) Finding the size of a data type


    157. Which operator is used to access members of an object through a pointer?

    a) .
    b) ->
    c) ::
    d) *
    Answer: b) ->


    158. What type of operator is new?

    a) Unary
    b) Binary
    c) Ternary
    d) None
    Answer: a) Unary


    159. Which operator has the highest precedence?

    a) +
    b) *
    c) ()
    d) =
    Answer: c) ()


    160. What does the ++ operator do?

    a) Increments a value
    b) Decrements a value
    c) Multiplies a value
    d) Adds two values
    Answer: a) Increments a value

    Next TopicUnit-1Unit-2 Unit-3Unit-4  , Unit-5 

    ← prevnext →




    No comments:

    Post a Comment