TRE4 C and C++ Quiz practice set 3
Que: (1). Which language is better for writing structured code?
Asked in BPSC TRE 1.0Que: (2). Which of the following is primarily a procedural programming language that supports structured programming?
Que: (3). What is the full form of FORTRAN?
Que: (4). Which programming language was specifically designed for business data processing?
Que: (5). What is the full form of BASIC?
Que: (6). Which of the following is a first-generation programming language?
Que: (7). Which type of language uses mnemonic instructions such as MOV, ADD and SUB?
Que: (8). Which translator typically translates an entire source program into machine code or another target form before execution?
Que: (9). Which language-processing approach generally executes program instructions through interpretation rather than requiring a separate compiled executable?
Que: (10). Which of the following is an object-oriented programming language?
Que: (11). Which language does a browser use to display information from the World Wide Web?
Asked in BPSC TRE 1.0Que: (12). What is the full form of HTML?
Que: (13). Which language is primarily used to style the appearance of web pages?
Que: (14). Which programming language is commonly used to add interactivity to web pages in a browser?
Que: (15). What is the full form of URL?
Que: (16). What is the full form of HTTP?
Que: (17). Which of the following is a web browser?
Que: (18). What is the primary function of a web server?
Que: (19). In web communication, which component typically sends an HTTP request to a web server?
Que: (20). Which HTML element is used to create a hyperlink?
Que: (21). Select the true statement for compiler.
Asked in BPSC TRE 1.0Que: (22). What is the primary function of a compiler?
Que: (23). Which translator converts assembly language into machine code?
Que: (24). Which statement best describes an interpreter?
Que: (25). What is the primary function of a linker?
Que: (26). Which system program loads an executable into memory for execution?
Que: (27). What is source code?
Que: (28). Which statement about object code is correct?
Que: (29). Which type of error is commonly detected during compilation?
Que: (30). Which of the following are commonly associated with the compilation process?
Que: (31). Which of the following is not a valid variable name in most programming languages?
Asked in BPSC TRE 1.0Que: (32). What is an identifier in programming?
Que: (33). Which of the following is a valid variable name in C?
Que: (34). Which of the following is a reserved keyword in C?
Que: (35). Are variable names case-sensitive in C?
Que: (36). Which character can be used at the beginning of a variable name in C?
Que: (37). Which of the following is not a valid variable name in C?
Que: (38). Which keyword is commonly used to declare a read-only variable in C++?
Que: (39). Which of the following is a valid variable name in Python?
Que: (40). Which statement about identifiers in C is correct?
Que: (41). If a semicolon is not used at the end of a statement, what message will be displayed by C++?
Asked in BPSC TRE 1.0Que: (42). What is the primary purpose of a semicolon in C++?
Que: (43). What is the likely result of compiling the following C++ code: int x = 10 cout << x;
Que: (44). What does a single semicolon represent in C++?
Que: (45). Which symbol normally terminates a simple statement in C++?
Que: (46). Which is the correct declaration of an integer variable in C++?
Que: (47). Which software detects and reports many syntax errors in C++ source code?
Que: (48). Which symbols are used to enclose a block of statements in C++?
Que: (49). Which is the correct syntax for a basic if statement in C++?
Que: (50). Which of the following can cause a syntax error in C++?
Que: (51). Which shortcut keys are used to compile and run a program in Turbo C++?
Asked in BPSC TRE 1.0Que: (52). Which shortcut key is used to compile a program in classic Turbo C++?
Que: (53). Which shortcut key is used to run a program in classic Turbo C++?
Que: (54). Which shortcut key displays the user screen in classic Turbo C++?
Que: (55). What is the primary function of a C++ compiler?
Que: (56). What happens when a C++ program contains a syntax error?
Que: (57). What is the main purpose of debugging a C++ program?
Que: (58). What is the full form of IDE in software development?
Que: (59). Which of the following is commonly part of building a C++ program?
Que: (60). In classic Turbo C++, which shortcut is used to view the output screen after running a program?
Que: (61). Which of the following is a user-defined header file extension used in C++?
Asked in BPSC TRE 1.0Que: (62). What is the primary purpose of a header file in C++?
Que: (63). Which preprocessor directive is used to include a header file in C++?
Que: (64). Which standard C++ header file is commonly used for input and output with cin and cout?
Que: (65). Which syntax is commonly used to include a user-defined header file named myheader.h?
Que: (66). Which file extension is commonly used for a C++ source file?
Que: (67). What is the main purpose of a header guard in C++?
Que: (68). Which of the following is a valid C++ preprocessor directive for defining a macro?
Que: (69). Which of the following is a common declaration found in a C++ header file?
Que: (70). Which statement about C++ header files is correct?
Que: (71). What will happen if the following C++ statement is compiled and executed? int *ptr = NULL; delete ptr;
Asked in BPSC TRE 1.0Que: (72). Which operator is used in C++ to dynamically allocate memory for a single object?
Que: (73). Which operator is used to release memory allocated for a single object using new in C++?
Que: (74). Which operator should be used to release a dynamically allocated array in C++?
Que: (75). What can happen if memory allocated using new is never released when it is no longer needed?
Que: (76). What is a dangling pointer in C++?
Que: (77). What happens if a program dereferences a null pointer in C++?
Que: (78). Which statement correctly allocates an array of 10 integers dynamically in C++?
Que: (79). What is the result of deleting the same dynamically allocated pointer twice?
Que: (80). Which statement correctly describes the difference between new and malloc in C++?
Que: (81). Which of the following correctly declares an array in C++?
Asked in BPSC TRE 1.0Que: (82). What is the index of the first element in a C++ array?
Que: (83). Which statement correctly initializes an integer array with three elements in C++?
Que: (84). What is the output of the following C++ code? int a[4] = {2, 4, 6, 8}; cout << a[2];
Que: (85). What happens to the remaining elements when an integer array is partially initialized using a brace-enclosed initializer?
Que: (86). Which expression accesses the third element of an array named arr in C++?
Que: (87). Which of the following is a valid declaration of a character array in C++?
Que: (88). What is the last valid index of an array declared as int nums[8]; in C++?
Que: (89). Which statement correctly describes a fixed-size built-in array in C++?
Que: (90). What is the output of the following C++ code? int a[3] = {5, 10, 15}; cout << a[0] + a[2];
Que: (91). What will be the output of the given C++ code that attempts to concatenate character arrays using the + operator?
Asked in BPSC TRE 1.0
#include <iostream>
#include <string>
using namespace std;
int main() {
char s1[6] = "Hello";
char s2[6] = "World";
char s3[12] = s1 + " " + s2;
cout << s3;
return 0;
}
Que: (92). What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
char s[] = "Hello";
cout << s;
return 0;
}
Que: (93). What will be the output of the following C++ code?
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char s[] = "HELLO";
cout << sizeof(s) << " " << strlen(s);
return 0;
}
Que: (94). What will be the output of the following C++ code using std::string?
#include <iostream>
#include <string>
using namespace std;
int main() {
string s1 = "Hello";
string s2 = "World";
cout << s1 + " " + s2;
return 0;
}
Que: (95). What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
char s[] = "CAT";
s[1] = 'X';
cout << s;
return 0;
}
Que: (96). What will be the output of the following C++ code using a character pointer?
#include <iostream>
using namespace std;
int main() {
char s[] = "HELLO";
char *p = s;
cout << *(p + 2);
return 0;
}
Que: (97). What will be the output of the following C++ code using strcat()?
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char s1[10] = "Hi";
char s2[] = "All";
strcat(s1, s2);
cout << s1;
return 0;
}
Que: (98). What will be the output of the following C++ code using substr()?
#include <iostream>
#include <string>
using namespace std;
int main() {
string s = "COMPUTER";
cout << s.substr(2, 3);
return 0;
}
Que: (99). What will be the output of the following C++ code using find()?
#include <iostream>
#include <string>
using namespace std;
int main() {
string s = "BPSC TRE";
cout << s.find("TRE");
return 0;
}
Que: (100). What will be the output of the following C++ code after appending a character sequence?
#include <iostream>
#include <string>
using namespace std;
int main() {
string s = "abc";
s += "d";
cout << s.length();
return 0;
}
Que: (101). How do structures and classes in C++ differ?
Asked in BPSC TRE 1.0Que: (102). What will be the output of the following C++ code?
#include <iostream>
using namespace std;
struct Student {
int marks;
};
int main() {
Student s;
s.marks = 85;
cout << s.marks;
return 0;
}
Que: (103). What happens when the following C++ code is compiled?
#include <iostream>
using namespace std;
class Student {
int marks;
};
int main() {
Student s;
s.marks = 90;
cout << s.marks;
return 0;
}
Que: (104). What is the default inheritance access mode for a class in C++ when no access specifier is written?
Que: (105). Which statement about constructors in C++ structures and classes is correct?
Que: (106). Which statement correctly describes member functions in C++ structures and classes?
Que: (107). What will be the output of the following C++ code?
#include <iostream>
using namespace std;
struct Data {
private:
int value = 7;
public:
int getValue() { return value; }
};
int main() {
Data d;
cout << d.getValue();
return 0;
}
Que: (108). Which access specifier controls access so that a member can be used within its class and its derived classes, but not directly from unrelated external code?
Que: (109). What will be the output of the following C++ code using default inheritance?
#include <iostream>
using namespace std;
class Base {
public:
int value = 25;
};
struct Derived : Base {};
int main() {
Derived d;
cout << d.value;
return 0;
}
Que: (110). What will happen when the following C++ code is compiled?
#include <iostream>
using namespace std;
class Base {
public:
int value = 10;
};
class Derived : Base {};
int main() {
Derived d;
cout << d.value;
return 0;
}
Que: (111). What is the use of ios::trunc mode in C++?
Asked in BPSC TRE 1.0Que: (112). Which C++ file mode is used to append data at the end of a file?
Que: (113). Which C++ file mode is used to open a file for reading?
Que: (114). Which C++ file mode is used to open a file in binary mode?
Que: (115). What generally happens when an existing file is opened using ofstream with the default output mode?
#include <fstream>
using namespace std;
int main() {
ofstream file("data.txt");
file << "Hello";
file.close();
return 0;
}
Que: (116). Which statement correctly describes ios::ate and ios::app in C++?
Que: (117). Which combination opens an existing file for both reading and writing without requesting truncation?
Que: (118). What does the following C++ program do to an existing file named data.txt?
#include <fstream>
using namespace std;
int main() {
ofstream file("data.txt", ios::out | ios::trunc);
file.close();
return 0;
}
Que: (119). What happens when an input file stream attempts to open a nonexistent file using ios::in?
#include <fstream>
#include <iostream>
using namespace std;
int main() {
ifstream file("missing.txt", ios::in);
cout << file.is_open();
return 0;
}
Que: (120). Which statement about combining C++ file-opening modes is correct?
Que: (121). Which of the following statements is/are correct about C++ file opening modes?
Asked in BPSC TRE 1.0Que: (122). Which operator is used to combine two or more C++ file opening modes?
Que: (123). Which access is requested by the following C++ statement?
fstream file("data.txt", ios::in | ios::out);
Que: (124). What happens when an existing file is opened using the following statement?
ofstream fout("data.txt");
Que: (125). Which file opening mode ensures that output is written at the end of a file?
Que: (126). What is the difference between ios::ate and ios::app?
Que: (127). What is the likely result of this code if data.txt does not exist?
fstream file("data.txt", ios::in | ios::out);
if (file.is_open())
cout << "Opened";
else
cout << "Failed";
Que: (128). Which statement opens a file for binary output?
Que: (129). What does the following C++ code do?
ofstream fout("log.txt", ios::out | ios::app);
fout << "New entry";
fout.close();
Que: (130). Which file opening mode combination requests both input and output in binary mode?
Que: (131). The correct statement for a function that takes a pointer to a float, a pointer to a pointer to a char and returns a pointer to a pointer to an integer is
Asked in BPSC TRE 1.0Que: (132). Which declaration defines a function that accepts a pointer to an integer and returns a pointer to a character?
Que: (133). Which declaration represents a function that accepts a pointer to a pointer to int and returns an int?
Que: (134). What is the type of p in the following C code?
int x = 10;
int *p1 = &x;
int **p = &p1;
Que: (135). What value is printed by the following C program?
#include <stdio.h>
int main(void)
{
int x = 25;
int *p = &x;
int **q = &p;
printf("%d", **q);
return 0;
}
Que: (136). Which declaration correctly defines a function that accepts a pointer to float and returns a pointer to pointer to char?
Que: (137). Which declaration represents a function accepting a pointer to a function that takes an int and returns an int?
Que: (138). What is the output of this C program?
#include <stdio.h>
int main(void)
{
int x = 5;
int *p = &x;
int **q = &p;
**q = 40;
printf("%d", x);
return 0;
}
Que: (139). Which statement about a function returning a pointer is correct in C?
Que: (140). What does the following declaration mean in C?
int **get_pointer(void);
Que: (141). What will be the output of the following C++ code?
Asked in BPSC TRE 1.0
#include <iostream>
using namespace std;
long factorial(long a)
{
if (a > 1)
return a * factorial(a + 1);
else
return 1;
}
int main()
{
long num = 3;
cout << num << "!=" << factorial(num);
return 0;
}
Que: (142). What is the output of the following C++ program?
#include <iostream>
using namespace std;
long factorial(long n)
{
if (n <= 1)
return 1;
return n * factorial(n - 1);
}
int main()
{
cout << factorial(4);
return 0;
}
Que: (143). Which statement correctly describes the base case in a recursive factorial function?
Que: (144). What is the output of the following C++ code?
#include <iostream>
using namespace std;
int fun(int n)
{
if (n == 0)
return 0;
return n + fun(n - 1);
}
int main()
{
cout << fun(4);
return 0;
}
Que: (145). What is the likely result of calling the following recursive function with n equal to 5?
int fun(int n)
{
if (n == 0)
return 1;
return fun(n + 1);
}
Que: (146). What will the following C++ code print?
#include <iostream>
using namespace std;
int factorial(int n)
{
if (n == 0)
return 1;
return n * factorial(n - 1);
}
int main()
{
cout << factorial(0);
return 0;
}
Que: (147). What is the output of this recursive C++ function?
#include <iostream>
using namespace std;
int fun(int n)
{
if (n == 1)
return 1;
return n * fun(n - 1);
}
int main()
{
cout << fun(5);
return 0;
}
Que: (148). What is the output of the following C++ program?
#include <iostream>
using namespace std;
int fun(int n)
{
if (n <= 1)
return 1;
n = n - 1;
return n + fun(n);
}
int main()
{
cout << fun(4);
return 0;
}
Que: (149). Which problem can occur when recursion has no reachable base case?
Que: (150). What is the output of the following C++ code?
#include <iostream>
using namespace std;
int fun(int n)
{
if (n <= 1)
return n;
return fun(n - 1) + fun(n - 2);
}
int main()
{
cout << fun(5);
return 0;
}
Que: (151). Which is correct syntax of inheritance in C++?
Asked in BPSC TRE 1.0Que: (152). What is the default inheritance access mode for a class in C++?
Que: (153). What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class Base
{
public:
int x = 10;
};
class Derived : public Base
{
};
int main()
{
Derived d;
cout << d.x;
return 0;
}
Que: (154). Which statement about protected members in C++ inheritance is correct?
Que: (155). What type of inheritance is demonstrated by the following C++ code?
class A { };
class B : public A { };
class C : public B { };
Que: (156). Which declaration correctly demonstrates multiple inheritance in C++?
Que: (157). What happens when a derived class directly accesses a private member of its base class?
#include <iostream>
using namespace std;
class Base
{
private:
int x = 5;
};
class Derived : public Base
{
public:
void show()
{
cout << x;
}
};
int main()
{
Derived d;
d.show();
return 0;
}
Que: (158). What is the purpose of virtual inheritance in C++?
Que: (159). What is the output of the following C++ code?
#include <iostream>
using namespace std;
class Base
{
public:
Base() { cout << "B"; }
};
class Derived : public Base
{
public:
Derived() { cout << "D"; }
};
int main()
{
Derived obj;
return 0;
}
Que: (160). What is the output of the following C++ code using virtual functions and inheritance?
#include <iostream>
using namespace std;
class Base
{
public:
virtual void show() { cout << "Base"; }
};
class Derived : public Base
{
public:
void show() override { cout << "Derived"; }
};
int main()
{
Derived d;
Base* p = &d;
p->show();
return 0;
}
Que: (161). Which one of the following is the correct definition of the is_array() function in PHP?
Asked in BPSC TRE 1.0Que: (162). What will be the output of the following PHP code?
<?php
$a = [10, 20, 30];
$b = 25;
var_dump(is_array($a));
var_dump(is_array($b));
?>
Que: (163). Which PHP function returns the number of elements in an array?
Que: (164). What will be the output of the following PHP code?
<?php
$user = ["name" => "Amit", "age" => 25];
echo is_array($user) ? "Yes" : "No";
?>
Que: (165). What will the following PHP code print?
<?php
$data = [[1, 2], [3, 4]];
echo is_array($data[0]) ? "Array" : "Not Array";
?>
Que: (166). What is the output of this PHP code?
<?php
$numbers = [10, 20, 30, 40];
echo $numbers[2];
?>
Que: (167). What will be the output of the following PHP code?
<?php
$data = [[1, 2], [3]];
echo count($data) . " ";
echo count($data, COUNT_RECURSIVE);
?>
Que: (168). What will be the output of this PHP code?
<?php
$value = "123";
var_dump(is_array($value));
?>
Que: (169). Which PHP function checks whether a specified value exists in an array?
Que: (170). What will be the output of the following PHP code?
<?php
function getData() {
return ["PHP", "C++"];
}
$result = getData();
echo is_array($result) ? "Array" : "Not Array";
?>
Que: (171). Which of the following statements is correct about a class and an object in C++?
Asked in BPSC TRE 1.0Que: (172). Which keyword is used to define a class in C++?
Que: (173). What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class Student
{
public:
int marks = 85;
};
int main()
{
Student s;
cout << s.marks;
return 0;
}
Que: (174). What is the default access specifier for members of a C++ class?
Que: (175). What will be the output of the following C++ program?
#include <iostream>
using namespace std;
class Demo
{
public:
Demo() { cout << "Hello"; }
};
int main()
{
Demo d;
return 0;
}
Que: (176). What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class Test
{
public:
static int count;
};
int Test::count = 10;
int main()
{
Test a, b;
a.count++;
cout << b.count;
return 0;
}
Que: (177). Which statement about constructors in C++ is correct?
Que: (178). What will be the output of the following C++ program?
#include <iostream>
using namespace std;
class Number
{
int value;
public:
Number(int value)
{
this->value = value;
}
void show()
{
cout << value;
}
};
int main()
{
Number n(25);
n.show();
return 0;
}
Que: (179). In a typical C++ implementation, what is the result of sizeof applied to an empty class?
#include <iostream>
using namespace std;
class Empty
{
};
int main()
{
cout << sizeof(Empty);
return 0;
}
Que: (180). Which object-oriented programming principle combines data and the functions that operate on that data into a single unit?
Que: (181). Which of the following can be used to create an abstract class in C++?
Asked in BPSC TRE 1.0Que: (182). Which is the correct syntax for declaring a pure virtual function in C++?
Que: (183). Can an object of an abstract class be created directly in C++?
Que: (184). What is the output of the following C++ program?
#include <iostream>
using namespace std;
class Base {
public:
virtual void show() = 0;
};
class Derived : public Base {
public:
void show() override {
cout << "Derived";
}
};
int main() {
Derived obj;
obj.show();
return 0;
}
Que: (185). What happens if a derived class does not override an inherited pure virtual function?
Que: (186). Which statement about constructors in an abstract C++ class is correct?
Que: (187). What is the output of the following C++ program?
#include <iostream>
using namespace std;
class Base {
public:
virtual void display() {
cout << "Base";
}
};
class Derived : public Base {
public:
void display() override {
cout << "Derived";
}
};
int main() {
Derived d;
Base* ptr = &d;
ptr->display();
return 0;
}
Que: (188). What is the output of the following C++ program?
#include <iostream>
using namespace std;
class Shape {
public:
virtual int area() = 0;
};
class Square : public Shape {
public:
int area() override {
return 4 * 4;
}
};
int main() {
Square s;
cout << s.area();
return 0;
}
Que: (189). Consider the following C++ code. Which statement is correct?
#include <iostream>
using namespace std;
class A {
public:
virtual void f() = 0;
};
int main() {
A* p = nullptr;
return 0;
}
Que: (190). Which statement about a pure virtual function in C++ is correct?
Que: (191). Which of the following statements is correct about the C++ programming language?
Asked in BPSC TRE 1.0Que: (192). When does static type checking primarily occur in C++?
Que: (193). What is the purpose of a const member function in C++?
Que: (194). What is the output of the following C++ program?
#include <iostream>
using namespace std;
class Test {
int x;
public:
Test() : x(10) {}
int getValue() const {
return x;
}
};
int main() {
const Test obj;
cout << obj.getValue();
return 0;
}
Que: (195). Which C++ feature enables a function call to be resolved at runtime based on the actual object type?
Que: (196). What is the output of the following C++ program?
#include <iostream>
using namespace std;
class Base {
public:
virtual void show() {
cout << "Base";
}
};
class Derived : public Base {
public:
void show() override {
cout << "Derived";
}
};
int main() {
Derived d;
Base* p = &d;
p->show();
return 0;
}
Que: (197). Which C++ operator is commonly used for runtime type checking and safe downcasting in a polymorphic class hierarchy?
Que: (198). What happens when a const object attempts to call a non-const member function in C++?
#include <iostream>
using namespace std;
class Test {
public:
void show() {
cout << "Hello";
}
};
int main() {
const Test obj;
obj.show();
return 0;
}
Que: (199). Which statement correctly describes function overloading and function overriding in C++?
Que: (200). What is the output of the following C++ program?
#include <iostream>
using namespace std;
void print(int x) {
cout << "int";
}
void print(double x) {
cout << "double";
}
int main() {
print(5);
return 0;
}
Que: (201). Which feature of OOP is indicated by the following code?
Asked in BPSC TRE 1.0
class student { int marks; };
class topper : public student {
int age;
topper(int age) { this->age = age; }
};
Que: (202). Which OOP concept allows a derived class to acquire accessible members of a base class?
Que: (203). Which OOP concept bundles data and the functions that operate on that data into a single unit?
Que: (204). What is the output of the following C++ program?
#include <iostream>
using namespace std;
class Student {
public:
int marks = 80;
};
class Topper : public Student {
public:
void display() {
cout << marks;
}
};
int main() {
Topper t;
t.display();
return 0;
}
Que: (205). Which access specifier makes a class member accessible only within the class and its friends?
Que: (206). What is the output of the following C++ program?
#include <iostream>
using namespace std;
class Test {
int x;
public:
Test(int x) {
this->x = x;
}
void display() {
cout << x;
}
};
int main() {
Test t(25);
t.display();
return 0;
}
Que: (207). Which feature of OOP allows the same interface to represent different underlying implementations?
Que: (208). What is the output of the following C++ program?
#include <iostream>
using namespace std;
class Base {
public:
virtual void show() {
cout << "Base";
}
};
class Derived : public Base {
public:
void show() override {
cout << "Derived";
}
};
int main() {
Derived d;
Base* p = &d;
p->show();
return 0;
}
Que: (209). What happens if a derived class inherits publicly from a base class whose public and protected members are accessible?
Que: (210). Consider the following C++ code. Which statement is correct?
#include <iostream>
using namespace std;
class Base {
private:
int x = 10;
protected:
int y = 20;
};
class Derived : public Base {
public:
void display() {
cout << y;
}
};
int main() {
Derived d;
d.display();
return 0;
}