Tap an option to check your answer — the correct answer and full explanation appear after you choose.
ProgrammingC++ ProgrammingPPSCFPSCNTSID: PROG-097
What is the output of this C++ code? int x = 3; x = x * x; cout << x;
A3.
B6.
C12.
D9. ✓ Correct answer
✓ Correct answer: 9.
Full explanation
9. In C++, x is 3, so x * x is 3 * 3, which is 9, and 9 is stored back in x. Why the others are wrong: 3. — 3 is the first value of x, not the result of x * x. 6. — 6 would be 3 + 3, not 3 * 3. 12. — 12 is not the result of 3 * 3.
ProgrammingC++ ProgrammingPPSCFPSCNTSID: PROG-102
In C++, what is 'cin' used for?
ATo store a number in memory
BTo print output on the screen
CTo read input from the keyboard ✓ Correct answer
DTo end a program
✓ Correct answer: To read input from the keyboard
Full explanation
To read input from the keyboard. In C++, cin reads values typed by the user on the keyboard and stores them in variables. Why the others are wrong: To print output on the screen — printing output on the screen is the job of cout, not cin. To store a number in memory — storing a number in memory is the job of a variable, not cin. To end a program — ending a program is done by return, not by cin.
ProgrammingC++ ProgrammingPPSCFPSCNTSID: PROG-107
What is the output of this C++ code? int x = 3; x *= 4; cout << x;
A3
B7
C34
D12 ✓ Correct answer
✓ Correct answer: 12
Full explanation
The output of the code is 12, because x *= 4 means x becomes 3 x 4, which is 12. Why the others are wrong: 7 — 7 would be the result of adding 3 and 4, but the code multiplies, not adds. 34 — 34 would be the two digits joined together, but the code does maths, not joining digits. 3 — 3 is the starting value of x, but the code changes it to 12. So the correct answer is 12.
ProgrammingC++ ProgrammingPPSCFPSCNTSID: PROG-112
In C++, what does the 'cin' command do?
AIt prints output on the screen
BIt stops the program
CIt creates a new file
DIt reads input from the user ✓ Correct answer
✓ Correct answer: It reads input from the user
Full explanation
It reads input from the user. In C++, cin takes values typed by the user and stores them in variables. Why the others are wrong: It prints output on the screen — output is printed on the screen with cout, not with cin. It stops the program — a program is stopped by a return statement, not by cin. It creates a new file — a new file is created with file commands, not with cin.
ProgrammingC++ ProgrammingPPSCFPSCNTSID: PROG-117
In C++, what does 'endl' do?
AIt reads input from the keyboard.
BIt stops the program.
CIt ends a line and moves to the next line. ✓ Correct answer
DIt saves a file.
✓ Correct answer: It ends a line and moves to the next line.
Full explanation
In C++, 'endl' does this: it ends a line and moves to the next line. Why the others are wrong: It reads input from the keyboard. — that is what 'cin' does, not 'endl'. It stops the program. — that is not what 'endl' does. It saves a file. — that is not what 'endl' does.
ProgrammingC++ ProgrammingBPSCID: BPP-865
Which term is used to write an object to disk?
ATokenization
BSerialization ✓ Correct answer
CDe-serialization
DNone of these
✓ Correct answer: Serialization
Full explanation
Serialization. Serialization converts an object into a format that can be stored on disk or transmitted over a network, and later reconstructed by deserialization.
ProgrammingC++ ProgrammingBPSCID: BPP-866
How is dynamically allocated memory de allocated in C++?
AUsing erase()
BAutomatically
CUsing delete ✓ Correct answer
DNone of these
✓ Correct answer: Using delete
Full explanation
Using delete. In C++, memory allocated with new is deallocated with delete, and memory allocated for arrays with new[] is freed with delete[].
ProgrammingC++ ProgrammingBPSCID: BPP-867
Which catch block should be written first when handling multiple exceptions?
AOrder Irrelevant
BGeneral
CSpecific ✓ Correct answer
DNone of these
✓ Correct answer: Specific
Full explanation
Specific. When handling multiple exceptions, specific catch blocks must come before general ones, because a general catch written first would catch the exception and the specific handlers would never run.
ProgrammingC++ ProgrammingBPSCID: BPP-868
Which keyword is used to define an exception block?
AFinally
BCatch
CTry ✓ Correct answer
DThrow
✓ Correct answer: Try
Full explanation
Try. The try block encloses code that may generate an exception; a matching catch block then handles the exception, and throw raises one.
ProgrammingC++ ProgrammingBPSCID: BPP-869
When overriding function which of following should be the same in base and derived class?
AFunction name
BReturn type
CBoth A and B ✓ Correct answer
DParameter list
✓ Correct answer: Both A and B
Full explanation
Both A and B. In function overriding, the function name and return type in the derived class must be the same as in the base class, and the parameter list is identical too.
ProgrammingC++ ProgrammingBPSCID: BPP-870
When overloading functions which of the following must be different?
AFunction name
BReturn type
CBoth A and B
DParameter list ✓ Correct answer
✓ Correct answer: Parameter list
Full explanation
Parameter list. Overloaded functions share the same name but must have different parameter lists (different number or types of parameters); return type alone cannot distinguish them.
ProgrammingC++ ProgrammingBPSCID: BPP-871
When overloading functions which of the following should be the same?
AFunction name ✓ Correct answer
BReturn type
CBoth A and B
DParameter list
✓ Correct answer: Function name
Full explanation
Function name. Function overloading requires the same function name with different parameter lists; the return type may be the same or different but cannot by itself distinguish overloads.
ProgrammingC++ ProgrammingBPSCID: BPP-872
Which feature simplifies complexity by emphasizing high-level design?
APolymorphism
BAbstraction ✓ Correct answer
CInheritance
DAll of them
✓ Correct answer: Abstraction
Full explanation
Abstraction. Abstraction hides implementation details and shows only the essential features, simplifying complexity by emphasising high-level design.
ProgrammingC++ ProgrammingBPSCID: BPP-873
Feature which enables objects of different classes to respond differently to the same message?
APolymorphism ✓ Correct answer
BAbstraction
CInheritance
DAll of them
✓ Correct answer: Polymorphism
Full explanation
Polymorphism. Polymorphism lets objects of different classes respond differently to the same message or function call, increasing flexibility and code reuse.
ProgrammingC++ ProgrammingBPSCID: BPP-874
Which of the following deals with protecting an object's internal data by controlling access?
APolymorphism
BEncapsulation ✓ Correct answer
CInheritance
DAll of them
✓ Correct answer: Encapsulation
Full explanation
Encapsulation. Encapsulation protects an object's internal data by hiding it and controlling access through methods, preserving data integrity and security.
ProgrammingC++ ProgrammingSTSID: LTP-1817
How many bits of a C++ integer are taken in memory?
A32 bits ✓ Correct answer
B16 bits
C24 bits
DNone of these
✓ Correct answer: 32 bits
Full explanation
32 bits. Data Type: int in C++ Memory Size: Usually 32 bits (4 bytes) on most modern systems Additional information : Can store values approximately from - 2,147,483,648 to 2,147,483,647 (signed int) Size may vary depending on compiler and system architecture (older systems used 16 bits)
ProgrammingC++ ProgrammingBPSCID: BPP-2122
A method can change attributes of an object because objects are passed by
Acopying objects
Bcopy constructors
Creference ✓ Correct answer
Dvalue
✓ Correct answer: reference
Full explanation
Objects are passed by reference, so a method can change the attributes of the original object.
ProgrammingC++ ProgrammingBPSCID: BPP-2123
If a class contains multiple methods sharing the same name but with different argument lists, it is
Aover burdened
Bover loaded ✓ Correct answer
Cover used
Dover ridden
✓ Correct answer: over loaded
Full explanation
A class with multiple methods sharing the same name but different argument lists is over loaded.
ProgrammingC++ ProgrammingBPSCID: BPP-2779
In object-oriented programming, the bundling of data and methods is called:
AEncapsulation ✓ Correct answer
BInheritance
CPolymorphism
DAbstraction
✓ Correct answer: Encapsulation
Full explanation
Encapsulation is the bundling of data and methods within a class in object-oriented programming.
ProgrammingC++ ProgrammingBPSCID: BPP-2780
In object-oriented programming, a class acquiring properties of another class is called:
AInheritance ✓ Correct answer
BPolymorphism
CAbstraction
DEncapsulation
✓ Correct answer: Inheritance
Full explanation
Inheritance is the mechanism by which a class acquires the properties of another class.