16 Programming in C/C++ (Computer Science) questions asked in BPSC TRE previous year papers, each with the correct answer and explanation. Read them free on UTpaper, or attempt the full papers as timed online tests.
What will happen if in a C++ program, a class has no name?
AIt is not even allowed in C++
BIt will not have the constructor
CIt will not have the destructor
DMore than one of the above
ENone of the above
Show answerHide answer
Correct answer: (C) It will not have the destructor
Explanation
An unnamed class is allowed, but a destructor is declared with the class name, so such a class cannot declare a destructor; the official key is (C).
Q6BPSC TRE 3.0 (2024) Computer Science Class 11-12
#include <stdio.h>
int main()
{
int i = 5, j = 10, k = 15;
printf("%d ", sizeof(k /=i+j));
printf("%d", k);
return 0;
}
Assume size of an integer as 4 bytes. What is the output of above program?
A2 1
B4 1
C4 15
DMore than one of the above
ENone of the above
Show answerHide answer
Correct answer: (C) 4 15
Explanation
sizeof only looks at the type of its operand and does not evaluate the expression, so k /= i+j never runs. It prints 4 (size of int), then k is still 15.
Q7BPSC TRE 1.0 (2023) Computer Science Class 11-12
Which shortcut key is used to compile and run the program in C++?
AAlt+F9
BAlt+F5
CCtrl+F9
DMore than one of the above
ENone of the above
Show answerHide answer
Correct answer: (C) Ctrl+F9
Explanation
In Turbo C++, Ctrl+F9 compiles and runs the program. Alt+F9 only compiles, and Alt+F5 shows the output screen.
Q8BPSC TRE 1.0 (2023) Computer Science Class 11-12
Which of the following is userdefined header file extension used in C++?
Ahg
Bcpp
Ch
DMore than one of the above
ENone of the above
Show answerHide answer
Correct answer: (C) h
Explanation
User-defined header files in C++ use the .h extension, for example #include "myfile.h". .cpp is used for source files.
Q9BPSC TRE 1.0 (2023) Computer Science Class 11-12
How do structures and classes in C++ differ?
AStructures by default hide every member whereas classes do not
BIn structures, members are public by default, whereas, in classes, they are private by default
CStructures cannot have private members, whereas classes can have
DMore than one of the above
ENone of the above
Show answerHide answer
Correct answer: (D) More than one of the above
Explanation
Note: the answer key gives (D), but only (B) is correct: struct members are public by default and class members are private by default. C++ structures can also have private members, so (C) is false.
Q10BPSC TRE 1.0 (2023) Computer Science Class 11-12
Which of the following statements is correct about the C++ programming language?
AIn C++, both the static and dynamic types checking are allowed.
BIn C++, member function are allowed to be of the type const.
CIn C++, dynamic checking is allowed.
DMore than one of the above
ENone of the above
Show answerHide answer
Correct answer: (D) More than one of the above
Explanation
All three statements are true. C++ does static type checking at compile time and dynamic checking with RTTI and dynamic_cast, and member functions can be declared const.
Q11BPSC TRE 2.0 (2023) Computer Science Class 11-12
All members of a structure in C++ are _____ by default.
Apublic
Bprivate
Cprotected
DMore than one of the above
ENone of the above
Show answerHide answer
Correct answer: (A) public
Explanation
In C++, members of a struct are public by default, and so is struct inheritance. This is the main difference from a class.
Q12BPSC TRE 2.0 (2023) Computer Science Class 11-12
In C++, all members of a class are _____ by default.
Apublic
Bprivate
Cprotected
DMore than one of the above
ENone of the above
Show answerHide answer
Correct answer: (B) private
Explanation
In C++, members of a class are private by default unless an access specifier says otherwise.
Q13BPSC TRE 2.0 (2023) Computer Science Class 11-12
Which of the following is used to define the members of a class externally in C++?
A:
B: :
C#
DMore than one of the above
ENone of the above
Show answerHide answer
Correct answer: (B) : :
Explanation
The scope resolution operator :: defines a member function outside its class, for example void A::show() { }.
Q14BPSC TRE 2.0 (2023) Computer Science Class 11-12
What will be the output of the following program fragment?
int i = 10;
void main( )
{ int i = 20;
{
int i = 30;
printf("%d, %d", i, ::i);
}
}
A30,10
B30,20
C20,30
DMore than one of the above
ENone of the above
Show answerHide answer
Correct answer: (A) 30,10
Explanation
The innermost i is 30. ::i is the scope resolution operator and refers to the global i, which is 10, so the output is 30,10. Note that :: is valid in C++, not C.
Q15BPSC TRE 2.0 (2023) Computer Science Class 11-12
Choose the correct statement about inline function in C++.
AIt speeds up the execution.
BIt slows down the execution.
CIt decreases the code size.
DMore than one of the above
ENone of the above
Show answerHide answer
Correct answer: (A) It speeds up the execution.
Explanation
An inline function's body is substituted at the call site, so there is no function-call overhead and execution is faster. It usually makes the code bigger, not smaller.
Q16BPSC TRE 2.0 (2023) Computer Science Class 11-12
cout in C++ stands for
Aclass output
Bcharacter output
Ccommon output
DMore than one of the above
ENone of the above
Show answerHide answer
Correct answer: (C) common output
Explanation
Official BPSC answer key: (C). Note: most textbooks expand cout as “character output” (B).
How to use these BPSC TRE Computer Science questions
Every question here was asked in a real BPSC TRE paper; the paper and shift are shown on the card, and the number opens the question on its own page. Try each one before tapping Show answer, then attempt the full BPSC TRE papers as timed tests to check your speed under exam conditions.