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 121

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

What will be the Output of following javascript ?

<script language=“javascript”> javascript:function x ( ) { var qpt = “First come, first served”; var pattern = /first/g; document.write(qpt.match(pattern) [ 1 ]); } x ( ) ;   </script>
  1. AOption (a)

    first

  2. BOption (b)

    First

  3. COption (c)

    undefined

  4. DOption (d)

    None of the above

View answer & explanation

Correct answer

Answer: (c)C.

undefined

Why this answer is correct

The correct answer is : option 3

Key Points

In JavaScript, the String.prototype.match() method is used to retrieve the result of matching a string against a regular expression.

If the regular expression has the g flag, it returns an array of all matches.

Code:

<script language="javascript"> function x() { var qpt = "First come, first served"; var pattern = /first/g; document.write(qpt.match(pattern)[1]); } x(); </script>

Step-by-Step Explanation:

  1. qpt = "First come, first served"
  2. pattern = /first/g → case-sensitive match for "first"
  3. qpt.match(pattern) will return: ["first"]
  4. match()[1] tries to access the second element (index 1) of the result array.
  5. But only one match ("first") is found → match() returns an array with 1 element.
  6. match()[1] → undefined

Important Note: The pattern does not match "First" because regular expressions are case-sensitive by default.

Final Output: undefined

Correct Answer: Option 3) undefined ✅

Question 122

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

What will be the output of the following code segment ?

int rem_dup(int a[], int n){

int j = 1, k = 0, b[20];

b[0] = a[0];

while (j < n) {

while (j < n && a[j] == a[j – 1])

j++;

if ( j < n)

b[++k] = a[j++];

}

for (j = 0; j <= k; j++)

a[j] = b[j];

n = k + 1;

}

main() {

int i, n = 12;

int a[ ] = {1,1,1,3,4,4,5,8,8,10,11,11};

rem_dup(a, n);

printf(“After removing duplicates: ”);

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

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

}

  1. AOption (a)

    After removing duplicates : 1 3 4 5 8 10 11 8 8 10 11 11

  2. BOption (b)

    After removing duplicates : 1 3 4 5 8 10 11 

  3. COption (c)

    After removing duplicates : 1 1 1 3 4 4 5 8 8 10 11 11

  4. DOption (d)

    After removing duplicates : 1 3 4 5 8 10

View answer & explanation

Correct answer

Answer: (a)A.

After removing duplicates : 1 3 4 5 8 10 11 8 8 10 11 11

Why this answer is correct

The correct answer is : option 1

Key Points

This function rem_dup() removes duplicates from a sorted array and stores only the unique elements in-place in the original array using a temporary array b[]. However, the function does not return the updated value of n, so the main function still uses the original value of n = 12 in the loop.

Initial Array:

int a[] = {1, 1, 1, 3, 4, 4, 5, 8, 8, 10, 11, 11}; int n = 12;

Step-by-Step Execution of rem_dup():

  • b[0] = a[0] = 1
  • Skip repeated 1s → j = 3, insert 3
  • Skip one 4 → insert 4
  • Insert 5
  • Skip one 8 → insert 8
  • Insert 10
  • Skip one 11 → insert 11

Resulting b[] = {1, 3, 4, 5, 8, 10, 11}

These values are copied back to a[] at the beginning of the array.

But in main():

  • n remains 12 because the function does not return or update it outside.
  • So the loop prints first 12 elements of array a[].

Final content of a[]:

a[] = {1, 3, 4, 5, 8, 10, 11, 8, 8, 10, 11, 11}

Output Printed:

After removing duplicates: 1 3 4 5 8 10 11 8 8 10 11 11

Correct Answer: Option 1) After removing duplicates: 1 3 4 5 8 10 11 8 8 10 11 11 ✅

Question 123

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

______________ defines the speed of network access.

  1. AOption (a)

    RAM

  2. BOption (b)

    MHz

  3. COption (c)

    Kbps

  4. DOption (d)

    Megabytes

View answer & explanation

Correct answer

Answer: (c)C.

Kbps

Why this answer is correct

The correct answer is Kbps

Key Points

  • Kbps (Kilobits per second): ✅ Kbps is a unit of measurement used to define the speed of data transfer or network access. It indicates how many kilobits of data can be transmitted per second over a network connection.
  • RAM: ❌ RAM (Random Access Memory) refers to the memory used by a device to store temporary data, not network speed.
  • MHz: ❌ MHz (Megahertz) is a unit of frequency, often used to measure the speed of a processor or clock cycles, not network access speed.
  • Megabytes: ❌ Megabytes measure data storage or file size, not the speed of network access.

Additional Information

  • Speed Measurement: Network speeds are commonly measured in units such as Kbps, Mbps (Megabits per second), or Gbps (Gigabits per second).
  • Modern Standards: Modern internet speeds are often measured in Mbps or Gbps, which are much faster than Kbps. However, Kbps was commonly used for older technologies like dial-up connections.

Hence, the correct answer is: option 3) Kbps

Question 124

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

If a signal is attenuated by a factor of 10, ________ is the loss in dB.

  1. AOption (a)

    10

  2. BOption (b)

    100

  3. COption (c)

    1/10

  4. DOption (d)

    1/100

View answer & explanation

Correct answer

Answer: (a)A.

10

Why this answer is correct

The correct answer is : option 1 

Key Points

When a signal is attenuated, it means that the output power is less than the input power. Decibels (dB) provide a logarithmic way to express this ratio.

Formula for attenuation in dB (for power):

Loss (in dB) = 10 × log10(Pin / Pout)

Given:

  • Signal is attenuated by a factor of 10
  • So, Pout = Pin / 10

Substitute in the formula:

Loss = 10 × log10(Pin / (Pin / 10)) = 10 × log10(10) = 10 × 1 = 10 dB

Final Answer: 10 dB

Correct Option: Option 1) 10 ✅

Question 125

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

How do you delete an element from an options array ?

  1. AOption (a)

    Set it to false

  2. BOption (b)

    Set it to null

  3. COption (c)

    Set it to undefined

  4. DOption (d)

    Set it to – 1

View answer & explanation

Correct answer

Answer: (c)C.

Set it to undefined

Why this answer is correct

The correct answer is Set it to undefined

Key Points

  • Set to undefined: ✅ Setting an element in an array to undefined removes its value without impacting the length of the array. The index remains in the array but becomes undefined.
  • Set to false: ❌ Setting an element to false does not delete it; it simply assigns the boolean value false to that index.
  • Set to null: ❌ Setting an element to null assigns the value null to that index but does not delete it or remove it from the array.
  • Set to –1: ❌ Setting an element to -1 simply assigns the value -1 to that index. It does not remove or delete the element.

Additional Information

  • Array Length: Using undefined will not reduce the length of the array. If you want to remove an element and adjust the array length, use methods like splice() or filter().
  • Best Practice: While setting an element to undefined is one way to "delete" its value, it is generally better to use splice() to remove the element entirely if you want to reindex the array.

Hence, the correct answer is: option 3) Set it to undefined

Question 126

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

Overloading is an example of

  1. AOption (a)

    Runtime polymorphism

  2. BOption (b)

    Compile time polymorphism

  3. COption (c)

    Abstraction

  4. DOption (d)

    None of the above

View answer & explanation

Correct answer

Answer: (b)B.

Compile time polymorphism

Why this answer is correct

The correct answer is Compile time polymorphism

Key Points

  • Overloading: ✅ Overloading is an example of compile-time polymorphism because it is resolved during the compilation of the program. It occurs when multiple methods have the same name but differ in the number or type of parameters.
  • Runtime polymorphism: ❌ Runtime polymorphism is achieved through method overriding, which is resolved during program execution and involves dynamic dispatch.
  • Abstraction: ❌ Abstraction refers to hiding implementation details and showing only the essential features, which is a different concept unrelated to overloading.
  • None of the above: ❌ This option is incorrect because overloading clearly falls under compile-time polymorphism.

Additional Information

  • Compile-time polymorphism: This type of polymorphism is determined at compile time and does not involve dynamic method invocation.
  • Examples: Method overloading and operator overloading are classic examples of compile-time polymorphism.

Hence, the correct answer is: option 2) Compile time polymorphism

Question 127

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

Ten out of fourteen stations on a LAN accept the same transmission. The destination address is probably a ___________ address.

  1. AOption (a)

    unicast

  2. BOption (b)

    multicast

  3. COption (c)

    broadcast

  4. DOption (d)

    None of the above

View answer & explanation

Correct answer

Answer: (c)C.

broadcast

Why this answer is correct

The correct answer is broadcast

Key Points

  • Unicast: ❌ Unicast communication involves a single sender and a single receiver. It is a one-to-one communication. Since 10 out of 14 stations received the transmission, this is not a unicast address.
  • Multicast: ❌ Multicast communication involves sending data to a specific group of recipients rather than all the devices on the network. However, in this scenario, the transmission is accepted by 10 stations, which doesn't indicate group-specific targeting.
  • Broadcast: ✅ Broadcast communication sends the data to all devices on the LAN. If 10 out of 14 stations accept the transmission, it is likely a broadcast address, as all devices on the network are targeted, and only the ones configured to accept the broadcast respond.
  • None of the above: ❌ This option is incorrect, as the correct category is clearly broadcast.

Additional Information

  • Broadcast Address: A broadcast address allows the transmission of data to all devices within the same network segment. In Ethernet LANs, the broadcast address is typically represented as FF:FF:FF:FF:FF:FF (all bits set to 1 in the MAC address).
  • LAN Communication: On a LAN, devices may either ignore or process broadcast transmissions based on their configuration or relevance of the data.

Hence, the correct answer is: option 3) broadcast

Question 128

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

Suppose an array is defined as a[ ] = {1, 2, 3, 4, 5} and there is a linked list whose nodes are defined as

struct node {

int n; 

struct node *next;

};

If the linked list also has 5 nodes then which of the following statement will be false ?

  1. AOption (a)

    Elements of a will be contiguous in memory but the nodes of the linked list will be non-contiguous. 

  2. BOption (b)

    Both a and the linked list will occupy same amount of memory space.

  3. COption (c)

    To reach the ith element of the linked list, it is necessary to traverse all the nodes before it but not so for array elements.

  4. DOption (d)

    Both array and the linked list will have homogeneous elements.

View answer & explanation

Correct answer

Answer: (b)B.

Both a and the linked list will occupy same amount of memory space.

Why this answer is correct

Correct Answer: Option 2) ❌ False

Key Points

Arrays and linked lists are both linear data structures, but they differ significantly in memory allocation, access methods, and internal representation.

Given:

int a[] = {1, 2, 3, 4, 5}; // An array of 5 integers

struct node { int n; struct node *next; }; // A singly linked list of 5 nodes

Option Analysis:

Option 1: Elements of a will be contiguous in memory but the nodes of the linked list will be non-contiguous.

✅ True — Arrays are stored in contiguous memory locations. Linked list nodes are dynamically allocated and may be scattered in memory.

Option 2: Both a and the linked list will occupy same amount of memory space.

❌ False — Arrays of 5 integers use 5 × sizeof(int) bytes. But in linked lists, each node stores: int n + pointer to next, which is sizeof(int) + sizeof(pointer) per node. So total memory used is higher in linked list.

Option 3: To reach the ith element of the linked list, it is necessary to traverse all the nodes before it but not so for array elements.

✅ True — Arrays support direct access using indexing (O(1)). Linked lists require traversal from the head to reach the ith node (O(i)).

Option 4: Both array and the linked list will have homogeneous elements.

✅ True — Both structures store integers (homogeneous data type).

Correct Answer: Option 2) ❌ False

Question 129

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

Matrices with high proportion of zeros are called

  1. AOption (a)

    square matrices 

  2. BOption (b)

    zero matrix

  3. COption (c)

    Sparse matrix 

  4. DOption (d)

    identity matrix

View answer & explanation

Correct answer

Answer: (c)C.

Sparse matrix 

Why this answer is correct

The correct answer is Sparse Matrix

Key Points

  • Sparse Matrix: ✅ Sparse matrices are matrices in which most of the elements are zero. These matrices are common in applications like numerical computations, graph theory, and machine learning.
  • Square Matrix: ❌ A square matrix has the same number of rows and columns, but does not necessarily have a high proportion of zeros.
  • Zero Matrix: ❌ A zero matrix is a matrix where all elements are zero. However, this is not the definition of matrices with a high proportion of zeros, as sparse matrices can have non-zero elements.
  • Identity Matrix: ❌ An identity matrix is a square matrix with ones on the main diagonal and zeros elsewhere, not a matrix with a high proportion of zeros in general.

Additional Information

  • Applications: Sparse matrices are used in solving large systems of linear equations, storing graphs in adjacency matrices, and data compression techniques.
  • Efficiency: Sparse matrices are stored using specialized data structures (like compressed sparse row or compressed sparse column formats) to optimize memory usage and computation speed.

Hence, the correct answer is: option 3) Sparse Matrix

Question 130

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

Which of the following is an infinite loop ?

  1. AOption (a)

    i = 0;

    while (i < 10) {

    if (i == 3)

    break;

    printf(“%d”, i);

    i++;

    }

  2. BOption (b)

    i = 0;

    do {

    if (i++ == 3)

    continue;

    printf(“%d”, i);

    } while (i < 10);

  3. COption (c)

    for (i = 0; i < 10; i++) {

    if (i == 3)

    continue;

    printf(“%d”, i);

    }

  4. DOption (d)

    int i = 0;

    while (i < 10) {

    if (i == 3)

    continue;

    printf(“%d”, i);

    i++;

    }

View answer & explanation

Correct answer

Answer: (d)D.

int i = 0;

while (i < 10) {

if (i == 3)

continue;

printf(“%d”, i);

i++;

}

Why this answer is correct

Correct Answer: Option 4) ✅ Infinite Loop

Key Points

An infinite loop is a loop that never terminates due to a missing or incorrect exit condition or due to a logic error that prevents reaching the exit condition.

Option Analysis:

Option 1:

i = 0; while (i < 10) { if (i == 3) break; printf("%d", i); i++; }

✅ NOT an infinite loop — The loop breaks when i == 3.

Option 2:

i = 0; do { if (i++ == 3) continue; printf("%d", i); } while (i < 10);

✅ NOT an infinite loop — i increments on every iteration due to i++ in if(), and will eventually reach 10.

Option 3:

for (i = 0; i < 10; i++) { if (i == 3) continue; printf("%d", i); }

✅ NOT an infinite loop — The continue skips printing for i==3, but the loop continues and terminates at i==10.

Option 4:

int i = 0; while (i < 10) { if (i == 3) continue; printf("%d", i); i++; }

❌ Infinite loop — When i == 3, the continue skips the i++ statement, so i remains 3 forever. The loop keeps checking i == 3 and never exits.

Correct Answer: Option 4) ✅ Infinite Loop