Search Previous Year Questions

Find real questions from previous competitive exam papers with answers and solutions.

Leave the keyword blank to browse saved questions for your selected exam, newest papers first. Add a keyword, year or topic to narrow the results.

Browse complete papers
Showing 10 question(s)
Clear

Question 81

UP police programmer Grade 2 2013• Part 2: Computer Programming

What is garbage collection in the context of Java ? 

  1. AOption (a)

    The operating system periodically deletes all of the java files available on the system. 

  2. BOption (b)

    Any package imported in a program and not used is automatically deleted.

  3. COption (c)

    The JVM checks the output of any Java program and deletes anything that doesn’t make sense. 

  4. DOption (d)

    When all references to an object are gone, the memory used by the object is automatically reclaimed.

View answer & explanation

Correct answer

Answer: (d)D.

When all references to an object are gone, the memory used by the object is automatically reclaimed.

Why this answer is correct

The correct answer is option 4

Key Points

  • Garbage collection: ✅ In Java, garbage collection is an automatic memory management process handled by the Java Virtual Machine (JVM). When all references to an object are gone, the memory occupied by the object is automatically reclaimed.
  • Incorrect options:
  • Option 1: ❌ The operating system does not delete Java files periodically. This is unrelated to garbage collection.
  • Option 2: ❌ Unused imported packages are not deleted automatically. This is a static code issue, not related to memory management.
  • Option 3: ❌ The JVM does not check the output of a program to delete anything nonsensical. This is a misinterpretation of garbage collection.

Additional Information

  • Automatic memory management: Java simplifies memory management by automatically reclaiming memory through garbage collection, allowing developers to focus on core logic instead of manual memory allocation and deallocation.
  • Garbage collector: The garbage collector is a part of the JVM responsible for finding unused objects and reclaiming memory.
  • Finalization: Before an object is collected, its finalize() method (if overridden) is called to release resources like file handles or network connections.

Hence, the correct answer is: option 4) When all references to an object are gone, the memory used by the object is automatically reclaimed.

Question 82

UP police programmer Grade 2 2013• Part 2: Computer Programming

Match the protocol with its port number:

a.FTP data transferi)53
b.Telnetii)23
c.TFTP (Trivial File Transfer)iii)69
d.DNS (domain Name Server)iv)161
e.SNMP (Simple Network Management Protocol)v)20
  1. AOption (a)

    a-v, b-ii, c-iii, d-i, e-iv

  2. BOption (b)

    a-i, b-v, c-ii, d-iii, e-iv

  3. COption (c)

    a-v, b-iii, c-ii, d-i, e-iv

  4. DOption (d)

    a-v, b-iv, c-ii, d-i, e-iii

View answer & explanation

Correct answer

Answer: (a)A.

a-v, b-ii, c-iii, d-i, e-iv

Why this answer is correct

The correct answer is option 1: a-v, b-ii, c-iii, d-i, e-iv.

Key Points

  • FTP data transfer corresponds to port 20 (v).
  • Telnet corresponds to port 23 (ii).
  • TFTP (Trivial File Transfer Protocol) corresponds to port 69 (iii).
  • DNS (Domain Name Server) corresponds to port 53 (i).
  • SNMP (Simple Network Management Protocol) corresponds to port 161 (iv).

Additional Information

  • FTP (File Transfer Protocol): Used to transfer files over a network. It uses ports 20 for data transfer and 21 for commands.
  • Telnet: A protocol used for remote login to a server. It uses port 23.
  • TFTP (Trivial File Transfer Protocol): A simpler version of FTP used for transferring files. It uses port 69.
  • DNS (Domain Name Server): Resolves domain names to IP addresses. It uses port 53.
  • SNMP (Simple Network Management Protocol): Used for managing network devices. It uses port 161.

Question 83

UP police programmer Grade 2 2013• Part 2: Computer Programming

int A[ ] = {2,3,6,7,9} ;

int *p = A;

for (int i = 0 ; i< 5; ++i)

{

(*p) ++ ;

cout << A [i] ;

}

Output of the above code is:

  1. AOption (a)

    3 4 7 8 10

  2. BOption (b)

    2 3 6 7 9

  3. COption (c)

    3 3 6 7 9

  4. DOption (d)

    3 4 6 7 9

View answer & explanation

Correct answer

Answer: (c)C.

3 3 6 7 9

Why this answer is correct

The correct answer is option 3) 3 3 6 7 9

Key Points

  • Initial Array: int A[] = {2, 3, 6, 7, 9};
  • Pointer Declaration: int *p = A; → p points to the first element of the array A[0]
  • Inside Loop:
  • (*p)++; increments the value at p, i.e., A[0] becomes 3
  • Then cout << A[i]; prints each A[i] from 0 to 4
  • Key Observation:
  • p is never incremented, so (*p)++; always modifies A[0]
  • So, in every loop iteration, A[0] gets incremented once

Step-by-step Array Status:

  • Before loop: A = {2, 3, 6, 7, 9}
  • i=0 → (*p)++ → A[0]=3 → print A[0]=3
  • i=1 → (*p)++ → A[0]=4 → print A[1]=3
  • i=2 → (*p)++ → A[0]=5 → print A[2]=6
  • i=3 → (*p)++ → A[0]=6 → print A[3]=7
  • i=4 → (*p)++ → A[0]=7 → print A[4]=9

Final Output: 3 3 6 7 9

Additional Information

  • *(p)++: This is equivalent to incrementing the value pointed by p (A[0] in this case).
  • Pointer is not incremented: So only A[0] changes during the loop.
  • Array values accessed by A[i] are printed each time, unaffected except A[0].

Hence, the correct answer is: option 3) 3 3 6 7 9

Question 84

UP police programmer Grade 2 2013• Part 2: Computer Programming

What will be the output of the following code segment if it is invoked using the statement Mystery (234) ?

int Mystery (int n){

if (n < = 0)

return n; return (n % 10) + Mystery (n / 10);

}

  1. AOption (a)

    9

  2. BOption (b)

    432

  3. COption (c)

    234

  4. DOption (d)

    24

View answer & explanation

Correct answer

Answer: (a)A.

9

Why this answer is correct

The correct answer is option 1) 9

Key Points

int Mystery(int n) { if (n <= 0) return n; return (n % 10) + Mystery(n / 10); }

  • Function Definition:
  • This function returns the sum of digits of the number n.
  • n % 10 gives the last digit.
  • n / 10 removes the last digit.

Step-by-step Execution for Mystery(234):

  • Mystery(234) → (234 % 10) + Mystery(234 / 10)
  • = 4 + Mystery(23)
  • = 4 + (3 + Mystery(2))
  • = 4 + 3 + (2 + Mystery(0))
  • Mystery(0) → returns 0
  • So total = 4 + 3 + 2 + 0 = 9

Additional Information

  • Recursive base case: When n ≤ 0, return 0
  • Recursive case: Add last digit to result of recursion on remaining digits
  • This pattern is a classic way to sum digits of a number using recursion

Hence, the correct answer is: option 1) 9

Question 85

UP police programmer Grade 2 2013• Part 2: Computer Programming

What will be the output of the following code segment?

int *p, a [ ] = {23, 45, 67, 33, 81, 56}, i ;

for (p = a, i = 4; i >= 3; i--)

printf (“ \n%d %d”, *p + i, *(p + i)) ;

  1. AOption (a)

    27 81

    26 33

  2. BOption (b)

    24 33

    23 67

  3. COption (c)

    24 81

    23 33

  4. DOption (d)

    Some garbage values will be shown as output

View answer & explanation

Correct answer

Answer: (a)A.

27 81

26 33

Why this answer is correct

The correct answer is option 1) 27 81

26 33

Key Points

  • Given Array: a[] = {23, 45, 67, 33, 81, 56}
  • Pointer p: initialized as p = a; ⇒ p points to a[0]
  • Loop: for (i = 4; i ≥ 3; i--) → i = 4, 3
  • Each iteration prints:
  • *p + i → value at a[0] + i
  • *(p + i) → value at a[i]

Step-by-step Evaluation:

  • When i = 4:
  • *p = a[0] = 23
  • *p + i = 23 + 4 = 27
  • *(p + 4) = a[4] = 81
  • → prints: 27 81
  • When i = 3:
  • *p = a[0] = 23
  • *p + i = 23 + 3 = 26
  • *(p + 3) = a[3] = 33
  • → prints: 26 33

Final Output:

27 81 26 33

Additional Information

  • *p: Always points to a[0] as p is not incremented
  • *(p + i): Accesses a[i] directly using pointer arithmetic
  • This question tests understanding of pointer indexing and expressions like *p + i vs *(p + i)

Hence, the correct answer is: option 1)

Question 86

UP police programmer Grade 2 2013• Part 2: Computer Programming

Linked list is a

  1. AOption (a)

    Static data structure

  2. BOption (b)

    Homogeneous data structure

  3. COption (c)

    Heterogeneous data structure

  4. DOption (d)

    None of the above

View answer & explanation

Correct answer

Answer: (d)D.

None of the above

Why this answer is correct

The correct answer is None of the above

Key Points

  • Static Data Structure: ❌ A static data structure, such as an array, has a fixed size determined during compilation and cannot grow or shrink dynamically. Linked lists are dynamic and do not belong to this category.
  • Homogeneous Data Structure: ❌ Homogeneous data structures store elements of the same data type. Linked lists can store heterogeneous types if implemented using generic programming, making this option incorrect.
  • Heterogeneous Data Structure: ❌ While linked lists can store different types of data, they are primarily defined as dynamic data structures, so this option is not the most accurate description.

Additional Information

  • Dynamic Data Structure: Linked lists are dynamic data structures because they can grow and shrink during runtime by allocating or deallocating memory as needed.
  • Memory Utilization: Linked lists utilize memory efficiently by allocating memory only when required, unlike arrays which may lead to memory wastage due to fixed sizes.
  • Flexibility: Linked lists allow easy insertion and deletion of elements without the need for shifting elements, unlike arrays.

Hence, the correct answer is: option 4) None of the above

Question 87

UP police programmer Grade 2 2013• Part 2: Computer Programming

What will be the output of the following code segment ?

int i, a [ ] = {45,26,19,73,92} ;

for (i = 0; i < = 4 ; i++)

if (i % 3 != 0)

printf (“ %d ”, a[i]) ;

  1. AOption (a)

    45 26 19 73 92

  2. BOption (b)

    26 19 92

  3. COption (c)

    45 73

  4. DOption (d)

    73

View answer & explanation

Correct answer

Answer: (b)B.

26 19 92

Why this answer is correct

The correct answer is option 2) 26 19 92

Key Points

  • Array: a[] = {45, 26, 19, 73, 92}
  • Loop: for (i = 0; i <= 4; i++) → i goes from 0 to 4 (inclusive)
  • Condition: if (i % 3 != 0)

This skips any index i that is a multiple of 3 (like 0 and 3)

Step-by-step Iteration:

  • i = 0: 0 % 3 = 0 → Skipped
  • i = 1: 1 % 3 = 1 → ✅ Print a[1] = 26
  • i = 2: 2 % 3 = 2 → ✅ Print a[2] = 19
  • i = 3: 3 % 3 = 0 → Skipped
  • i = 4: 4 % 3 = 1 → ✅ Print a[4] = 92

Final Output: 26 19 92

Additional Information

  • Modulus Operator: i % 3 helps in skipping specific index positions based on a pattern.
  • Indexes skipped: 0 and 3 (as they are divisible by 3)
  • Indexes printed: 1, 2, 4

Hence, the correct answer is: option 2) 26 19 92

Question 88

UP police programmer Grade 2 2013• Part 2: Computer Programming

The TWO fields found in both TCP and UDP headers that are essential for multiplexing and de-multiplexing at the transport layer are _______

i) source port number

ii) source IP address

iii) destination host name

iv) destination port number

v) destination IP address

  1. AOption (a)

    i) & ii)

  2. BOption (b)

    i) & iv)

  3. COption (c)

    ii) & v) 

  4. DOption (d)

    iii) & iv)

View answer & explanation

Correct answer

Answer: (b)B.

i) & iv)

Why this answer is correct

The correct answer is: Option 2) i) & iv)

Key Points

  • Source Port Number (i): The source port number is used to identify the sending application or process on the sender's device. It is critical for ensuring that the correct application receives the response from the receiver.
  • Destination Port Number (iv): The destination port number identifies the receiving application or service on the destination device. It ensures that the data is delivered to the intended process.

Additional Information

  • Both source port number and destination port number are essential for multiplexing (sending data to the correct application) and de-multiplexing (receiving data at the correct application) at the transport layer.
  • These fields are present in both TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) headers. They allow the transport layer to distinguish between multiple applications running on the same device.
  • The other options, such as "source IP address," "destination IP address," and "destination host name," are not part of the transport layer headers. IP addresses are part of the network layer, and host names are resolved to IP addresses using DNS.

Hence, the correct answer is: Option 2) i) & iv)

Question 89

UP police programmer Grade 2 2013• Part 2: Computer Programming

The Stop and Wait protocol is executed on a 10km wire between your modem and your ISPs edge router. The propagation speed of an electrical signal on the wire is 200,000 km/sec. The packet size is 1000 bytes. The time to generate an acknowledgment by the receiver is 4 microseconds. The channel capacity is 100 Mbps. ______ is the maximum efficiency of the protocol.

  1. AOption (a)

    43.48%

  2. BOption (b)

    37.15%

  3. COption (c)

    53%

  4. DOption (d)

    100%

View answer & explanation

Correct answer

Answer: (a)A.

43.48%

Why this answer is correct

The correct answer is : option 1

Key Points

Step-by-Step Solution:

  • Distance (d): 10 km
  • Propagation speed (v): 200,000 km/s = 2 × 108 m/s
  • Packet size: 1000 bytes = 8000 bits
  • Channel capacity (R): 100 Mbps = 108 bps
  • Acknowledgment generation time: 4 μs = 4 × 10-6 s

1. Transmission Time (Ttrans):

Ttrans = Packet size / Channel capacity = 8000 bits / (108) = 0.00008 sec = 80 μs

2. Propagation Time (Tprop):

Tprop = Distance / Propagation speed = 10 × 103 m / (2 × 108 m/s) = 5 × 10-5 s = 50 μs

3. Total Cycle Time (Tcycle):

Tcycle = Ttrans + 2 × Tprop + ACK generation time = 80 + 2 × 50 + 4 = 184 μs

4. Efficiency (η):

η = Ttrans / Tcycle = 80 / 184 ≈ 0.4348 = 43.48%

✅ Correct Answer: Option 1) 43.48%

Question 90

UP police programmer Grade 2 2013• Part 2: Computer Programming

The data in ________ is not lost even if power is switched off. 

  1. AOption (a)

    files 

  2. BOption (b)

    arrays 

  3. COption (c)

    structures 

  4. DOption (d)

    unions

View answer & explanation

Correct answer

Answer: (a)A.

files 

Why this answer is correct

The correct answer is files

Key Points

  • Files: ✅ Data stored in files is permanent and is not lost even if the power is switched off. Files are stored on non-volatile storage devices such as hard drives, SSDs, or external storage.
  • Arrays: ❌ Arrays are stored in memory (RAM), which is volatile. Data in arrays is lost when the power is switched off.
  • Structures: ❌ Structures are a way to group variables in memory. Like arrays, they are stored in RAM and their data is lost when the power goes off.
  • Unions: ❌ Unions are similar to structures but share memory for their members. They are also stored in RAM and lose data when power is switched off.

Additional Information

  • Non-volatile storage: Devices like hard drives, SSDs, and USB drives are examples of non-volatile storage where files are stored. Data in such storage persists even after the power is switched off.
  • RAM (Volatile memory): Arrays, structures, and unions are typically stored in RAM, which is erased when the device is powered off.

Hence, the correct answer is: option 1) files