Home MCQs C++ Programming MCQS
MCQs

C++ Programming MCQS

C++ Programming MCQs with Answers – Important Questions

Practice MCQs Solved Questions Exam Preparation
17 Total MCQs
0 Topics
1 Past Papers

C++ Programming MCQS

Q1
In C/C++ Programming, the strcmp() function is used to:
A Convert String to Char
B Copy two Strings
C Compare two Strings
D None of these
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:
A Form feed
B Line Break
C Select All
D Alarm
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?
A Variable name must start with an underscore or letter
B Variable name must have a digit
C Variable name must have a whitespace character
D Keyword cannot be a variable name
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:
A Address of variable
B Value of the variable
C Either value or address
D Both value and address
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?
A &
B &&
C ||
D $$
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?
A Extern
B Register
C Global
D None of the above
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?
A All array variables have the same type
B An array is a collection of variables
C Array variables can be used individually
D None of these
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.
A Default Constructor
B Overloaded Constructor
C Default Object
D None of the above
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?
A Inheritance
B Composition
C Aggregation
D Association
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:
A An object is created in terms of a pre-existing object
B An object is created
C An object is initialized
D None of the above
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.
A Aggregation
B Composition
C Separation
D None of the given
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.
A class Supervisor public Person
B class Person : public Supervisor
C class Supervisor : public Person
D class Person:: public Supervisor
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.
A Aggregation
B Composition
C Inheritance
D Association
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.
A class Male; public Gender
B class Gender : public Male
C class Male : public Gender
D class Gender:: public Male
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:
A Take two arguments
B Take a single argument
C Take three arguments
D None of the given choices
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.
A class SpecialKeys public Keys
B class Keys : public SpecialKeys
C class SpecialKeys : public Keys
D class Keys public SpecialKeys
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.
A Object-Oriented Methods
B Object-Oriented Methods
C Object-Oriented Design
D Object-Oriented Programming
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.