BPSC TRE · Computer Science

Programming in C/C++ Previous Year Questions

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.

  • 16 questions
  • Official answer key
  • Free

Other Computer Science topics

Q1BPSC TRE 2.0 (2023) Computer Class 9-10
What is virtual inheritance in C++?
  1. AC++ technique to enhance multiple inheritance
  2. BC++ technique to ensure that a private member of the base class can be accessed somehow
  3. CC++ technique to avoid multiple copies of the base class into children/derived class
  4. DMore than one of the above
  5. ENone of the above
Show answerHide answer

Correct answer: (C) C++ technique to avoid multiple copies of the base class into children/derived class

Explanation

Virtual inheritance makes derived classes share one copy of a common base class, which avoids duplicate copies in diamond-shaped inheritance.

Q2BPSC TRE 2.0 (2023) Computer Class 9-10
Pick the incorrect statement about inline functions in C++.
  1. AThey save overhead of a return call from a function.
  2. BThey are generally very large and complicated function.
  3. CThese functions are inserted/substituted at the point of call.
  4. DMore than one of the above
  5. ENone of the above
Show answerHide answer

Correct answer: (B) They are generally very large and complicated function.

Explanation

Inline functions are meant for small, simple functions; saying they are generally very large and complicated is incorrect.

Q3BPSC TRE 2.0 (2023) Computer Class 9-10
What is abstract class in C++?
  1. AAny class in C++ is an abstract class/Class from which any class is derived
  2. BClass specifically used as a base class with at least one virtual function
  3. CClass specifically used as a base class with at least one pure virtual function
  4. DMore than one of the above
  5. ENone of the above
Show answerHide answer

Correct answer: (C) Class specifically used as a base class with at least one pure virtual function

Explanation

An abstract class is a base class that has at least one pure virtual function, so it cannot be instantiated.

Q4BPSC TRE 2.0 (2023) Computer Class 9-10
How do structures and classes in C++ differ?
  1. AIn structures, members are private by default whereas in classes, they are public by default
  2. BIn structures, members are public by default whereas in classes, they are private by default
  3. CStructures cannot have private members whereas classes can have
  4. DMore than one of the above
  5. ENone of the above
Show answerHide answer

Correct answer: (B) In structures, members are public by default whereas in classes, they are private by default

Explanation

In C++ the members of a struct are public by default, while those of a class are private by default.

Q5BPSC TRE 2.0 (2023) Computer Class 9-10
What will happen if in a C++ program, a class has no name?
  1. AIt is not even allowed in C++
  2. BIt will not have the constructor
  3. CIt will not have the destructor
  4. DMore than one of the above
  5. 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?
  1. A2 1
  2. B4 1
  3. C4 15
  4. DMore than one of the above
  5. 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++?
  1. AAlt+F9
  2. BAlt+F5
  3. CCtrl+F9
  4. DMore than one of the above
  5. 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++?
  1. Ahg
  2. Bcpp
  3. Ch
  4. DMore than one of the above
  5. 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?
  1. AStructures by default hide every member whereas classes do not
  2. BIn structures, members are public by default, whereas, in classes, they are private by default
  3. CStructures cannot have private members, whereas classes can have
  4. DMore than one of the above
  5. 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?
  1. AIn C++, both the static and dynamic types checking are allowed.
  2. BIn C++, member function are allowed to be of the type const.
  3. CIn C++, dynamic checking is allowed.
  4. DMore than one of the above
  5. 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.
  1. Apublic
  2. Bprivate
  3. Cprotected
  4. DMore than one of the above
  5. 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.
  1. Apublic
  2. Bprivate
  3. Cprotected
  4. DMore than one of the above
  5. 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++?
  1. A:
  2. B: :
  3. C#
  4. DMore than one of the above
  5. 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); } }
  1. A30,10
  2. B30,20
  3. C20,30
  4. DMore than one of the above
  5. 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++.
  1. AIt speeds up the execution.
  2. BIt slows down the execution.
  3. CIt decreases the code size.
  4. DMore than one of the above
  5. 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
  1. Aclass output
  2. Bcharacter output
  3. Ccommon output
  4. DMore than one of the above
  5. 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.

More BPSC TRE subjects