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 101

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

What will be the Output of following Javascript

<script language=“Javascript”> javascript:function x(){ x=4+“4”; document.write(x); } x ( ) ; </script>
  1. AOption (a)

    44

  2. BOption (b)

    8

  3. COption (c)

    4

  4. DOption (d)

    Error output

View answer & explanation

Correct answer

Answer: (a)A.

44

Why this answer is correct

The correct answer is option 1) 44

Key Points

  • Code:
<script language="Javascript"> javascript: function x() { x = 4 + "4"; document.write(x); } x(); </script>
  • Step-by-step Execution:
  • 4 + "4" = JavaScript performs string concatenation when one operand is a string.
  • 4 + "4" → "44" (number 4 is converted to a string and concatenated)
  • The result is stored in x, which is now a variable, not a function anymore.
  • document.write(x); writes "44" to the document.
  • Note: JavaScript allows overwriting functions with variables due to its dynamic nature, so no runtime error occurs.

Additional Information

  • In JavaScript, the + operator does numeric addition or string concatenation depending on operand types.
  • Functions can be reassigned as variables unless declared with const or let in strict mode.
  • The statement x = 4 + "4" replaces the function x() with a string value, but only after it is called.

Hence, the correct answer is: option 1) 44

Question 102

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

Which of the following statements is most appropriate for the code given below ?

int tryThis (char s[]) { int c1 = 0, c2 = 0, i = 0; for (i = 0; s[i]; i++) { if (i % 2 == 0) c1++; else c2++; } return c1 - c2; }

int main() { if (!tryThis("Palindromes")) printf("even"); else printf("odd"); }

  1. AOption (a)

    The program will not compile as the condition in for loop is not given properly.

  2. BOption (b)

    The program will not display anything as for loop is infinite.

  3. COption (c)

    The output of the program will be even.

  4. DOption (d)

    The output of the program will be odd.

View answer & explanation

Correct answer

Answer: (d)D.

The output of the program will be odd.

Why this answer is correct

the correct answer is : option 4) The output of the program will be odd.

Key Points

The given program defines a function tryThis() that takes a character array (string) as input and counts the number of characters at even and odd indices separately. It returns the difference between the counts. The main() function uses this result to print either "even" or "odd" depending on whether the result is zero or not.

Step-by-Step Execution:

Input String: "Palindromes" Length of the string = 11 Index positions: 0 1 2 3 4 5 6 7 8 9 10 Characters: P a l i n d r o m e s

Even indices (0, 2, 4, 6, 8, 10) → total = 6 characters → c1 = 6 Odd indices (1, 3, 5, 7, 9) → total = 5 characters → c2 = 5

Result of tryThis() = c1 - c2 = 6 - 5 = 1

In the main() function:

if (!tryThis("Palindromes")) → if (!1) → if (false) → So, else block executes → prints "odd"

Conclusion:

  • The program compiles and runs correctly.
  • The loop is not infinite, and the syntax is valid.
  • The result of the function is 1, which is not zero.
  • Therefore, the output will be "odd".

Correct Answer: Option 4) The output of the program will be odd ✅

Question 103

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

The value of the following prefix expression - + 3 *5/8 2 8 is

  1. AOption (a)

    5

  2. BOption (b)

    16

  3. COption (c)

    15

  4. DOption (d)

    25

View answer & explanation

Correct answer

Answer: (c)C.

15

Why this answer is correct

The correct answer is : option 3) 15

Key PointsA prefix expression (also known as Polish notation) is evaluated from right to left, where operators precede their operands.

We apply operations in the correct order of precedence based on the prefix format.

Given Expression:

    • 3 * 5 / 8 2 8

Step-by-Step Evaluation:

  1. / 8 2 → 8 / 2 = 4
  2. Now the expression becomes: - + 3 * 5 4 8
    • 5 4 → 5 * 4 = 20
  3. Now the expression becomes: - + 3 20 8
    • 3 20 → 3 + 20 = 23
  4. Now the expression becomes: - 23 8
  5. 23 - 8 → = 15

Final Answer: 15

Correct Option: Option 3) 15 ✅

Question 104

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

Which of the following code segments will correctly return the value in the first node of a linked list pointed to by front and also properly remove it from the linked list?

  1. AOption (a)

    int removeFromFront() {

    struct node *temp = front;

    front = front -> next;

    free(temp);

    return temp -> info;

    }

  2. BOption (b)

    int removeFromFront() {

    struct node *temp = front;

    front = front -> next;

    return temp -> info;

    free(temp);

    }

  3. COption (c)

    int removeFromFront(){

    int x = front -> info;

    front = front -> next;

    return x;

    }

  4. DOption (d)

    int removeFromFront(){

    int x = front -> info;

    struct node *temp = front;

    front = front -> next;

    free(temp);

    return x;

    }

View answer & explanation

Correct answer

Answer: (d)D.

int removeFromFront(){

int x = front -> info;

struct node *temp = front;

front = front -> next;

free(temp);

return x;

}

Why this answer is correct

The correct answer is : option 4

Key Points

When removing a node from the front of a singly linked list, we must:

  1. Store the value of the first node to return it later.
  2. Move the front pointer to the next node.
  3. Free the memory occupied by the removed node to avoid memory leaks.

 

Option Analysis:

Option 1:

int removeFromFront() { struct node *temp = front; front = front -> next; free(temp); return temp -> info; } Incorrect ❌ - Accessing temp->info after free(temp) causes undefined behavior.

Option 2:

int removeFromFront() { struct node *temp = front; front = front -> next; return temp -> info; free(temp); } Incorrect ❌ - free(temp) is never executed because it is after the return statement. This causes a memory leak.

Option 3:

int removeFromFront(){ int x = front -> info; front = front -> next; return x; } Incorrect ❌ - Does not free the removed node, resulting in a memory leak.

Option 4:

int removeFromFront(){ int x = front -> info; struct node *temp = front; front = front -> next; free(temp); return x; }

Correct ✅ - Stores the value, moves the front pointer, frees memory, and then returns the value. This is safe and efficient.

Final Answer: Option 4) ✅

Question 105

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

The last address of IP address represents

  1. AOption (a)

    Broadcast address

  2. BOption (b)

    Network address

  3. COption (c)

    Unicast address​

  4. DOption (d)

    None of the above

View answer & explanation

Correct answer

Answer: (a)A.

Broadcast address

Why this answer is correct

The correct answer is Broadcast address

Key Points

  • Broadcast Address: ✅ The last address in an IP address range within a network is the broadcast address. It is used to send data to all devices in the same network segment.
  • Network Address: ❌ The network address is the first address in the IP address range, used to identify the network itself and not a specific device.
  • Unicast Address: ❌ A unicast address is an address assigned to a single device for one-to-one communication, not the last address in the range.
  • None of the Above: ❌ This is incorrect as the last address does serve a specific purpose, which is the broadcast address.

Additional Information

  • Broadcast Address Definition: The broadcast address allows communication to all hosts on a network. For example, in a subnet like 192.168.1.0/24, the last address (192.168.1.255) is the broadcast address.
  • Significance: It is used by routers and devices to send data packets to all devices in the network without specifying individual addresses.
  • Calculation: The broadcast address can be calculated by filling all host bits in the subnet with binary 1s.

Hence, the correct answer is: option 1) Broadcast address

Question 106

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

What is the output produced by the following code ?

int a = 4;  int b = a;  int c = b;

a = a + 1; b = b + 2;  c = c + 3;

b = a; a = b;

System.out.println(“a: ’’ + a + “ b: ’’ + b + “ c: ’’ + c);

  1. AOption (a)

    a : 5 b : 5 c : 7

  2. BOption (b)

    a : 5 b : 5 c : 5 

  3. COption (c)

    a : 7 b : 7 c : 7 

  4. DOption (d)

    a : 6 b : 5 c : 7

View answer & explanation

Correct answer

Answer: (a)A.

a : 5 b : 5 c : 7

Why this answer is correct

The correct answer is : option 1

Key Points

This Java program demonstrates the use of basic variable assignments and arithmetic operations. Each variable assignment and update affects only the specific variable unless explicitly reassigned.

Code:

int a = 4; int b = a; int c = b;

a = a + 1; // a = 4 + 1 = 5 b = b + 2; // b = 4 + 2 = 6 c = c + 3; // c = 4 + 3 = 7

b = a; // b = 5 a = b; // a = 5 (already 5)

Final Values:

  • a = 5
  • b = 5
  • c = 7

Output:

a: 5 b: 5 c: 7

Correct Option: Option 1) a : 5 b : 5 c : 7 ✅

Question 107

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

______ OSI Model layer best describes the data integrity service.

  1. AOption (a)

    Physical 

  2. BOption (b)

    Transport 

  3. COption (c)

    Session

  4. DOption (d)

    Presentation

View answer & explanation

Correct answer

Answer: (b)B.

Transport 

Why this answer is correct

The correct answer is Transport

Key Points

  • Transport Layer: ✅ The Transport layer of the OSI model is responsible for providing reliable data transfer, which includes ensuring data integrity, error detection, and correction. It ensures that the data received is identical to the data sent.
  • Physical Layer: ❌ The Physical layer deals with the physical medium for data transmission (e.g., cables, connectors) and does not handle data integrity.
  • Session Layer: ❌ The Session layer manages and controls sessions between applications, ensuring proper synchronization but not data integrity.
  • Presentation Layer: ❌ The Presentation layer is responsible for data translation, encryption, and compression, but it does not handle data integrity services.

Additional Information

  • Data Integrity: The Transport layer ensures data integrity through mechanisms like error checking, acknowledgments, and retransmissions if errors are detected.
  • Protocols: Examples of protocols at the Transport layer include TCP (Transmission Control Protocol), which provides reliable communication, and UDP (User Datagram Protocol), which offers faster but less reliable communication.

Hence, the correct answer is: option 2) Transport

Question 108

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

Self referential structures are used to implement

  1. AOption (a)

    Call by value mechanism

  2. BOption (b)

    Call by reference mechanism

  3. COption (c)

    Recursion

  4. DOption (d)

    Linked lists

View answer & explanation

Correct answer

Answer: (d)D.

Linked lists

Why this answer is correct

The correct answer is Linked Lists

Key Points

  • Self-referential structures: ✅ Self-referential structures are used to create data structures where one or more members of the structure refer to the structure itself. This is essential for implementing linked lists, trees, and similar data structures.
  • Call by value mechanism: ❌ This concept involves passing a copy of the value to a function, which does not require self-referential structures.
  • Call by reference mechanism: ❌ This involves passing the reference of a variable to a function, unrelated to self-referential structures.
  • Recursion: ❌ While recursion involves a function calling itself, it does not inherently require self-referential structures.
  • Linked Lists: ✅ Linked lists are data structures where each node contains data and a reference to the next node. Self-referential structures are used to implement this "reference to the next node".

Additional Information

  • Structure Definition: A self-referential structure typically looks like:

    struct Node { int data; struct Node* next; // Reference to the same structure };

  • Usage: Self-referential structures are most commonly used in linked lists, queues, stacks, and trees.

  • Example: In a linked list, each node points to the next node, forming a chain-like connection.

Hence, the correct answer is: option 4) Linked Lists

Question 109

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 s= “Good100%”; var pattern = / \D/g; var output= s.match(pattern); document.write(output); }x(); </script>
  1. AOption (a)

    Good %

  2. BOption (b)

    1,0,0

  3. COption (c)

    G,o,o,d,%

  4. DOption (d)

    Error

View answer & explanation

Correct answer

Answer: (d)D.

Error

Why this answer is correct

The correct answer is : option 4

Key Points

This JavaScript code attempts to use a regular expression to extract non-digit characters from a string using the match() method.

Code:

<script language="javascript"> function x() { var s = "Good100%"; var pattern = / \D/g; var output = s.match(pattern); document.write(output); } x(); </script>

Explanation:

  • \D is a regular expression that matches any non-digit character.
  • However, the pattern used here is / \D/g which means: match a space character followed by a non-digit character.
  • In the string "Good100%", there is no space, so no match will be found.
  • match() will return null if no match is found.
  • So, document.write(output); will print null.

But there is another issue:

The script contains syntax errors:

  • The tag <script language=“javascript”> uses curly quotes (“ ”) instead of straight quotes (" ").
  • There is an unnecessary javascript: prefix before the function declaration.

 

Due to these syntax issues, the script will throw an error in the browser.

Correct Answer: Option 4) Error ✅

Question 110

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

Consider a circular queue of size 4. What is the position of front and rear after the following operations ?

Insert four elements A, B, C, D one after the other.

Delete element A and B and then insert element E.

  1. AOption (a)

    Front =0,rear=3(0 indicates first position) 

  2. BOption (b)

    Front =0,rear=4

  3. COption (c)

    Front =1,rear=3

  4. DOption (d)

    Front =2,rear=0

View answer & explanation

Correct answer

Answer: (d)D.

Front =2,rear=0

Why this answer is correct

The correct answer is : option 4

Key Points

A circular queue uses modulo arithmetic to wrap around the end of the array. We update front and rear using: rear = (rear + 1) % size and front = (front + 1) % size after insertion and deletion, respectively.

Given:

  • Queue size = 4
  • Initial positions: front = -1, rear = -1

Operations:

  1. Insert A:

front = 0, rear = 0 → Q = [A, _, _, _] 2. Insert B:

rear = (0 + 1) % 4 = 1 → Q = [A, B, _, _] 3. Insert C:

rear = (1 + 1) % 4 = 2 → Q = [A, B, C, _] 4. Insert D:

rear = (2 + 1) % 4 = 3 → Q = [A, B, C, D] 5. Delete A:

front = (0 + 1) % 4 = 1 → Q = [_, B, C, D] 6. Delete B:

front = (1 + 1) % 4 = 2 → Q = [_, _, C, D] 7. Insert E:

rear = (3 + 1) % 4 = 0 → Q = [E, _, C, D]

Final Positions:

  • Front = 2 (pointing to C)
  • Rear = 0 (pointing to E)

Correct Answer: Option 4) Front = 2, Rear = 0 ✅