MCQs
C++ Programming MCQS
C++ Programming MCQs with Answers – Important Questions
17
Total MCQs
0
Topics
1
Past Papers
C++ Programming MCQS
Q1
In C/C++ Programming, the strcmp() function is used to:
Explanation
The strcmp() function in C/C++ compares two null-terminated strings character by character. It returns 0 when the strings are equal, a negative value when the first string is smaller, and a positive value when the first string is larger.
Q2
In C/C++ Programming, "a" is used for:
Explanation
In C and C++, \a is an escape sequence that produces an alert or alarm character. On systems that support it, this may produce an audible beep or other alert.
Q3
Which of the following is the correct statement?
Explanation
In C/C++, an identifier such as a variable name must begin with a letter or underscore. It may contain letters, digits, and underscores afterward, but it cannot contain whitespace or be a reserved keyword.
Q4
While coding in C/C++, for "Call by Reference" we pass:
Explanation
In traditional C, call by reference is achieved by passing the address of a variable using a pointer. In C++, references can also be used to allow a function to operate directly on the original variable.
Q5
Which of the following is the symbol for the AND operator?
Explanation
The && operator is the logical AND operator in C and C++. It returns true when both conditions are true. The single & symbol is the bitwise AND operator.
Q6
Which of the following is not a type of variable?
Explanation
Extern and register are storage-related classifications in C/C++, while global describes a variable with global scope. Therefore, none of the listed choices is excluded as a variable type or classification.
Q7
Which of the following is the incorrect statement?
Explanation
An array is a collection of elements of the same data type. Its individual elements can be accessed using an index. Therefore, the statement that an array is simply a collection of variables is considered incorrect in this context.
Q8
To initialize an array of objects, only ______ will be called.
Explanation
When an array of objects is created without constructor arguments, the default constructor is invoked for each object. If constructor arguments are required, appropriate initialization must be provided.
Q9
What type of relationship exists between the Account class and the SavingAccount class?
Explanation
If SavingAccount is a specialized type of Account, then SavingAccount derives from the Account class. This represents an inheritance relationship, commonly expressed using public inheritance in C++.
Q10
A copy constructor is called when:
Explanation
A copy constructor is used to create and initialize a new object from an existing object of the same class. It is commonly invoked when an object is copied during initialization or passed by value.
Q11
In ______, a pointer or reference to an object is created inside a class.
Explanation
The question as written does not provide the standard relationship name for a class containing a pointer or reference to an object. Therefore, among the given choices, None of the given is the intended answer.
Q12
Select the correct line of code for the inheritance relationship between the Person class and the Supervisor class.
Explanation
In C++, the syntax class Supervisor : public Person declares Supervisor as a derived class of Person. This establishes a public inheritance relationship where Supervisor inherits accessible public and protected members of Person.
Q13
In ______, a pointer or reference to an object is created inside a class.
Explanation
Aggregation is a relationship in which one class contains a reference or pointer to an object of another class, while the contained object can exist independently of the containing object.
Q14
Select the correct line of code for the inheritance relationship between the Gender class and the Male class.
Explanation
The statement class Male : public Gender declares Male as a derived class of Gender. The colon followed by public specifies public inheritance in C++.
Q15
For the statement std3 = std1 - std2 to work correctly, the overloaded - operator must:
Explanation
When the binary - operator is overloaded as a member function, the left operand is the calling object and the right operand is passed as one argument. Therefore, the overloaded operator function takes a single explicit argument.
Q16
Select the correct line of code for the inheritance relationship between the Keys class and the SpecialKeys class.
Explanation
The statement class SpecialKeys : public Keys declares SpecialKeys as a derived class of Keys. It means SpecialKeys inherits the accessible public and protected members of Keys.
Q17
______ is concerned with realizing a software design using an object-oriented programming language.
Explanation
Object-Oriented Programming (OOP) is concerned with implementing software using an object-oriented programming language. It uses concepts such as classes, objects, inheritance, polymorphism, encapsulation, and abstraction.