DSSSB TGT / PGT · Topic-wise previous year questions
Computer Science Previous Year Questions (page 37)
2444 Computer Science questions asked in DSSSB TGT / PGT previous year papers, each with the correct answer and explanation. Read them free on UTpaper, or attempt the full papers as timed online tests.
Which of the following statements regarding the Best Fit memory allocation strategy is
true?
ABest Fit may cause excessive fragmentation by creating many small unusable holes.
BBest Fit always allocates memory faster since it searches the larger free partition.
CBest Fit prefers allocating memory at the start of the memory block list.
DBest Fit merges adjacent free partitions soon after allocation.
Show answerHide answer
Correct answer: (A) Best Fit may cause excessive fragmentation by creating many small unusable holes.
Explanation
Best Fit chooses the smallest hole that fits, so the leftover pieces are tiny and often too small to use, causing external fragmentation. It also searches the entire list, so it is not faster.
Which of the following statements about WITH CHECK OPTION in SQL views is true?
AIt ensures that inserted/updated rows satisfy the view’s WHERE clause.
BIt prevents any alter through the view.
CIt allows only ALTER operations on the view.
DIt makes the view read-only.
Show answerHide answer
Correct answer: (A) It ensures that inserted/updated rows satisfy the view’s WHERE clause.
Explanation
WITH CHECK OPTION rejects any INSERT or UPDATE through the view that would produce a row not satisfying the view's WHERE condition (a row that would vanish from the view).
Which of the following is true about FCFS disk scheduling?
AIt provides the best throughput compared to other algorithms.
BIt ensures the shortest seek time first.
CIt causes minimal delay for all processes.
DIt serves requests in the order they are received.
Show answerHide answer
Correct answer: (D) It serves requests in the order they are received.
Explanation
FCFS (first come, first served) serves disk requests strictly in arrival order. It is fair and simple, but it does not minimise seek time or give the best throughput.
What is a transport layer address typically called?
ASubnet Mask
BPort Numbe
CMAC Address
DIP Address
Show answerHide answer
Correct answer: (B) Port Numbe
Explanation
The transport layer identifies a process on a host by a port number (16 bits in TCP/UDP). MAC addresses belong to the data link layer and IP addresses to the network layer.
Which of the following is NOT a phase of TCP congestion control?
ASlow start
BData fragmentation
CFast retransmit
DCongestion avoidance
Show answerHide answer
Correct answer: (B) Data fragmentation
Explanation
TCP congestion control uses slow start, congestion avoidance, fast retransmit and fast recovery. Fragmentation of data is done at the IP (network) layer, not a congestion control phase.
Which of the following correctly describes a TCP connection termination?
AIt is immediate and requires no acknowledgment.
BIt does not involve the FIN flag.
CIt uses a two-way handshake.
DIt ensures both the sender and receiver agree to close the connection.
Show answerHide answer
Correct answer: (D) It ensures both the sender and receiver agree to close the connection.
Explanation
TCP connection termination is graceful: each side sends a FIN and the other acknowledges it (a four-way exchange), so both ends agree to close. It is not immediate and does use the FIN flag.
SELECT MAX(result) FROM student WHERE result < (SELECT MAX(result) FROM
student);
ASELECT result FROM student WHERE ROWNUM = 2 ORDER BY result DESC;
BSELECT TOP 2 result FROM student ORDER BY result DESC;
CSELECT result FROM student ORDER BY result DESC LIMIT 1 OFFSET 1;
DSELECT MAX(result) FROM student WHERE result < (SELECT MAX(result) FROM
student);
Show answerHide answer
Correct answer: (D) SELECT MAX(result) FROM student WHERE result < (SELECT MAX(result) FROM
student);
Explanation
Note: the question statement is missing in the source paper; only the SQL query shown above and the options were printed. The official answer key marks option 4 (the same query as the one shown).
While creating a new table ProductOrder_2026, which SQL statement correctly inserts
all the records from the ProductOrder_2026 table into ProductOrder?
ACREATE TABLE ProductOrder_2026 AS CREATE * FROM ProductOrder;
BCREATE TABLE ProductOrder_2026 AS SELECT * FROM ProductOrder;
CCREATE TABLE ProductOrder_2026 AS UPDATE * FROM ProductOrder;
DCREATE TABLE ProductOrder_2026 AS INSERT * FROM ProductOrder ;
Show answerHide answer
Correct answer: (B) CREATE TABLE ProductOrder_2026 AS SELECT * FROM ProductOrder;
Explanation
CREATE TABLE new_table AS SELECT * FROM old_table creates the new table and copies all rows of the old one into it. CREATE, UPDATE or INSERT cannot follow AS here.
Which of the following conditions must be satisfied to solve the critical section
problem?
ASemaphore, mutex, and locks
BMutual exclusion, progress, and bounded waiting
CPriority inversion, deadlock, and throughput
DStarvation, fairness, and scheduling
Show answerHide answer
Correct answer: (B) Mutual exclusion, progress, and bounded waiting
Explanation
A correct solution to the critical-section problem must satisfy mutual exclusion, progress and bounded waiting. Semaphores, mutexes and locks are tools for achieving this, not the conditions.
What will be the output of the following code?
#include <stdio.h>
int main() {
int x = 5;
switch(x) {
case 5:
printf("Five");
default:
printf("Default");
}
return 0;
}
ADefault
BCompilation error
CFive
DFiveDefault
Show answerHide answer
Correct answer: (D) FiveDefault
Explanation
case 5 matches and prints "Five". There is no break, so control falls through to default and also prints "Default", giving FiveDefault.
Correct answer: (B) The variable contains garbage (indeterminate) value.
Explanation
A local (automatic) variable that is not initialised holds an indeterminate (garbage) value. The program still compiles and runs, but results are unpredictable.
Consider the following Java code snippet:
class Animal {
String name;
int age;
Animal() {
this.name = "Unknown";
this.age = 0;
}
Animal(String name, int age) {
this.name = name;
this.age = age;
}
void displayInfo() {
System.out.println("Animal: " + name + ", Age: " + age);
}
}
public class Main {
public static void main(String[] args) {
Animal a1 = new Animal();
Animal a2 = new Animal("Dog", 5);
a1.displayInfo();
a2.displayInfo();
// Error-prone code:
//1. Animal a3 = new Animal("Cat");
//2. a2.name = null; a2.displayInfo();
// 3. Animal a4 = null; a4.displayInfo();
}
}
Which of the following statements is/are true regarding the above code?
1. The Animal class supports both default and parameterized constructors.
2. If line 1 in the comment is uncommented, the code will compile and run successfully.
3. If line 2 is executed, a2.displayInfo() will print "Animal: null, Age: 5".
4. If line 3 is executed, the program will throw a NullPointerException at runtime.
A1 and 4 only
B2 only
C1,2 and 4 only
D1,3 and 4 only
Show answerHide answer
Correct answer: (D) 1,3 and 4 only
Explanation
1 is true (no-arg and two-arg constructors). 2 is false: there is no Animal(String) constructor, so it would not compile. 3 is true: concatenating null prints "null". 4 is true: calling a method on a null reference throws NullPointerException.
What is the output of the following code?
#include <stdio.h>
int main() {
printf("%d", printf("C Programming"));
return 0;
}
A13
BC Programming
CC Programming12
DC Programming13
Show answerHide answer
Correct answer: (D) C Programming13
Explanation
The inner printf runs first, prints "C Programming" and returns the number of characters printed, 13. The outer printf then prints 13, giving "C Programming13".
Which of the following demonstrates the implementation of inheritance in Java?
Aclass B inherits A {}
Bclass A contains B {}
Cclass A implements B {}
Dclass A extends B {}
Show answerHide answer
Correct answer: (D) class A extends B {}
Explanation
Java uses the keyword extends for class inheritance, e.g. class A extends B. implements is used when a class implements an interface; inherits and contains are not Java keywords.
Consider the following code snippet. What will it print?
#include <stdio.h>
int main() {
char str[][10] = {"one", "two", "three"};
printf("%c\n", str[2][4]);
return 0;
}
Ar
Be
Cthree
Dh
Show answerHide answer
Correct answer: (B) e
Explanation
str[2] is "three" and indexing from 0 gives t(0), h(1), r(2), e(3), e(4), so str[2][4] is 'e'.
Given the following code, what will be the result?
public class Test {
public static void main(String[] args) {
Object obj = new String("Hello");
String str = (String) obj;
System.out.println(str);
}
}
AThrows ClassCastException.
BRuntime error.
CHello will be printed.
DCompilation error.
Show answerHide answer
Correct answer: (C) Hello will be printed.
Explanation
obj actually refers to a String object, so the downcast (String) obj succeeds at run time and "Hello" is printed. ClassCastException occurs only when the object is not of the target type.
What will be the output of the following code?
#include <stdio.h>
int main() {
int arr[5] = {10, 20, 30, 40, 50};
int (*p)[5] = &arr;
printf("%d\n", *(*p + 3));
return 0;
}
A40
B30
C20
DCompilation Error
Show answerHide answer
Correct answer: (A) 40
Explanation
p points to the whole array, so *p is arr (the address of its first element). *p + 3 points to arr[3], and dereferencing gives 40.
What will be printed by the following code?
#include<stdio.h>
int main() {
int marks = 75;
char grade = (marks >= 90) ? 'A' : (marks >= 70) ? 'B' : 'C';
printf("%c", grade);
return 0;
}
AB
BCompile time error
CA
DC
Show answerHide answer
Correct answer: (A) B
Explanation
75 >= 90 is false, so the second condition is checked: 75 >= 70 is true, so grade is 'B'.
Which among the following is an example of compile-time polymorphism in Java?
AMethod overriding
BInterfaces
CAbstract classes
DMethod overloading
Show answerHide answer
Correct answer: (D) Method overloading
Explanation
Method overloading (same name, different parameter lists) is resolved by the compiler, so it is compile-time (static) polymorphism. Method overriding is resolved at run time.
What will be the output of the following code (assume size of int as 4 bytes in the
system)?
#include<stdio.h>
int main() {
int arr[5] = {1, 2, 3, 4, 5};
printf("%lu", sizeof(arr));
return 0;
}
A20
B5
Ccompile time error
D4
Show answerHide answer
Correct answer: (A) 20
Explanation
sizeof on an array gives its total size in bytes: 5 elements x 4 bytes = 20.
In the context of array types, what is the key difference between int *arr[5] and int (*arr)
[5]?
ABoth are syntactically incorrect
BFirst is a pointer to an array, second is an array of pointers
CThey are identical in their functionality
DFirst is an array of pointers to integers, second is a pointer to an array of integers
Show answerHide answer
Correct answer: (D) First is an array of pointers to integers, second is a pointer to an array of integers
Explanation
[] binds tighter than *, so int *arr[5] is an array of 5 pointers to int. The parentheses in int (*arr)[5] make arr a single pointer to an array of 5 ints.
What will be the output of the following code?
#include <stdio.h>
int main() {
int a = 2, b = 3;
switch (a) {
case 1:
printf("Case 1");
break;
case 2:
switch (b) {
case 3:
printf("Case 3");
break;
default:
printf("Inner Default");
}
default:
printf("Outer Default");
}
return 0;
}
ACase 3Inner Default
BCase 3
CInner DefaultOuter Default
DCase 3Outer Default
Show answerHide answer
Correct answer: (D) Case 3Outer Default
Explanation
a = 2 selects case 2; the inner switch matches case 3, prints "Case 3", and its break exits only the inner switch. With no break after it, control falls into the outer default and prints "Outer Default".
Which type of applications are commonly developed using Object-Oriented
Programming?
AOperating system kernals
BMachine-level programs
CMobile applications
DAssembly-level programs
Show answerHide answer
Correct answer: (C) Mobile applications
Explanation
Mobile apps (Android in Java/Kotlin, iOS in Swift) and other large application software are commonly built with OOP. OS kernels and machine- or assembly-level programs are usually written in procedural C or assembly.
Which of the following is true about passing arguments by reference in PHP functions?
AArguments passed by reference cannot be modified within the function.
BThe original value of the argument is changed when passed by reference.
CPHP does not support passing arguments by reference.
DArguments passed by reference must be of type array.
Show answerHide answer
Correct answer: (B) The original value of the argument is changed when passed by reference.
Explanation
In PHP, a parameter declared with & (function f(&$x)) is a reference to the caller's variable, so changing it inside the function changes the original value. Any type can be passed by reference.
Which of the following is NOT a property of any algorithms?
ASome of the algorithms may not produce even single quantity as an output.
BEvery algorithm must produce at least one quantity as an output.
CEach instruction of the algorithm must be clear and unambiguous.
DFor all cases, the algorithm must terminate after finite number of instructions.
Show answerHide answer
Correct answer: (A) Some of the algorithms may not produce even single quantity as an output.
Explanation
Every algorithm must produce at least one output, have clear and unambiguous steps and terminate after finitely many steps. So "may not produce any output" is not a property of an algorithm.
Given the array a = [10, 20, 30, 40, 50, 60] with 6 elements,
What will the array look like after inserting the value 45 at index 4?
A[10, 20, 30, 40, 45, 50, 60]
B[10, 20, 25, 30, 40, 45, 50]
C[10, 20, 25, 30, 40, 45, 60]
D[10, 25, 20, 30, 40, 45, 50]
Show answerHide answer
Correct answer: (A) [10, 20, 30, 40, 45, 50, 60]
Explanation
Inserting 45 at index 4 shifts 50 and 60 one place right, giving [10, 20, 30, 40, 45, 50, 60]. The other options contain 25, which was never in the array.
BTo store data in a format that is readable by humans only
CTo enhance the visual appearance of a webpage
DTo represent and exchange data between different systems and platforms
Show answerHide answer
Correct answer: (D) To represent and exchange data between different systems and platforms
Explanation
XML is a platform-independent, self-describing text format used to store, represent and exchange structured data between different systems and applications. Presentation is the job of HTML/CSS.
What does the 'clone stamp' tool do in image editing?
ADuplicates part of the image to another area
BRemoves background
CResizes the image
DChanges the image color
Show answerHide answer
Correct answer: (A) Duplicates part of the image to another area
Explanation
The clone stamp copies (samples) pixels from one area of an image and paints them onto another area, often used to remove blemishes or duplicate objects.
Which of the following is an application of the World Wide Web?
ACreating software programs
BSending emails directly to a mobile phone
CBrowsing websites and accessing online services
DStoring files on a computer
Show answerHide answer
Correct answer: (C) Browsing websites and accessing online services
Explanation
The World Wide Web is a system of linked web pages accessed through browsers, used for browsing websites and online services such as shopping, banking and searching.
Suppose there are 15 elements in the array that apply bubble sort technique to sort the
elements of the array. What is the maximum number of comparisons, in worst case,
required to sort the elements of array in ascending order?
A120
B210
C105
D225
Show answerHide answer
Correct answer: (C) 105
Explanation
Bubble sort makes (n-1) + (n-2) + ... + 1 = n(n-1)/2 comparisons in the worst case. For n = 15 that is 15 x 14 / 2 = 105.
Which of the following is the correct way to declare a variable in Java?
Alet x = 10;
Bx = 10;
Cvar x = 10;
Dint x = 10;
Show answerHide answer
Correct answer: (D) int x = 10;
Explanation
Java is statically typed, so a variable is declared with its type: int x = 10;. let is JavaScript, and var x = 10 works only as local type inference from Java 10, so the standard answer is int.
Consider a singly linked list containing n elements in which A is the address of the
starting node of the linked list. If we first convert the linked list to an array, then sort the
array elements, and then create a new linked list from the elements of the sorted array,
what is the number of operations required to traverse the linked list and store its data
values in an additional array before applying sorting?
AO(n log n)
BO(log n)
CO(n)
DO(n²)
Show answerHide answer
Correct answer: (C) O(n)
Explanation
Copying the data needs a single pass through the list, visiting each of the n nodes once, so it takes O(n) operations. The later sorting step is what needs O(n log n).
fclose(fp) closes a file opened with fopen and flushes its buffers. close() is the low-level POSIX call on file descriptors, not the standard C file function.
Which method is used to loop through all the enumerable properties of an object in
JavaScript?
AObject.values()
BforEach()
Cfor...in
DObject.keys()
Show answerHide answer
Correct answer: (C) for...in
Explanation
The for...in loop iterates over all enumerable property names (keys) of an object. Object.keys() and Object.values() only return arrays, and forEach is an array method.
Suppose there are n elements in an array. If we want to delete the beginning element of an array, then how many shift operations are required to fill the gap left by the deleted element?
An*(n − 1)/2
Bn − 1
C1
Dn²
Show answerHide answer
Correct answer: (B) n − 1
Explanation
After deleting a[0], each of the remaining n - 1 elements must move one position left, so n - 1 shift operations are needed.
Consider the given memory representation of singly linked list where start points to the address of the starting node of the linked list, which is in memory location 0.
Memory representation of the linked list
Memory location | Item value | Pointer to next element
0 | A | 4
1 | E | 3
2 | B | NULL
3 | X | 2
4 | C | 1
If you traverse all the elements from the given linked list, then which of the following is correct order?
AA, B, C, E, X
BA, E, B, X, C
CA, C, X, E, B
DA, C, E, X, B
Show answerHide answer
Correct answer: (D) A, C, E, X, B
Explanation
Start at location 0 (A, next 4), then 4 (C, next 1), 1 (E, next 3), 3 (X, next 2), 2 (B, next NULL). So the order is A, C, E, X, B.
Which of the following are key components of an XML document?
ATags, attributes, and comments
BHTML tags and hyperlinks
CClasses, objects, and functions
DScripts, styles, and images
Show answerHide answer
Correct answer: (A) Tags, attributes, and comments
Explanation
An XML document is made of elements (tags), attributes, text content, comments and a prolog/declaration. HTML tags, classes or scripts are not its components.
What will be the output of the following C program code if the file "test.txt" is empty,
readable, and exists in the appropriate directory?
#include <stdio.h>
int main() {
FILE *fp = fopen("test.txt", "r");
if (fp == NULL) {
printf("Error\n");
} else {
printf("Success\n");
fclose(fp);
}
return 0;
}
ASuccess
BNULL
CGarbage value
DError
Show answerHide answer
Correct answer: (A) Success
Explanation
fopen in "r" mode succeeds for an existing readable file even if it is empty, so fp is not NULL and "Success" is printed. Emptiness only matters when reading data.
How to use these DSSSB TGT / PGT Computer Science questions
Every question here was asked in a real DSSSB TGT / PGT 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 DSSSB TGT / PGT papers as timed tests to check your speed under exam conditions.