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 111

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

In TCP, the path 

  1. AOption (a)

    up to destination is allocated before the transmission of message begins 

  2. BOption (b)

    up to next intermediate node is allocated before the transmission of message begins 

  3. COption (c)

    to be followed depends on the length of message

  4. DOption (d)

    none of the above

View answer & explanation

Correct answer

Answer: (a)A.

up to destination is allocated before the transmission of message begins 

Why this answer is correct

The correct answer is option 1

Key Points

  • TCP Path Allocation: ✅ In Transmission Control Protocol (TCP), the path up to the destination is allocated before the transmission of a message begins. This ensures that the entire route is established, and resources are reserved for reliable data transfer.
  • Intermediate Node Allocation: ❌ The path is not allocated up to the next intermediate node before transmission in TCP. This characteristic is more aligned with protocols like Datagram Packet Switching (UDP).
  • Message Length Dependency: ❌ The path to be followed does not depend on the length of the message in TCP. TCP ensures reliable delivery of data regardless of its size.
  • None of the Above: ❌ Since option 1 is correct, "none of the above" is not applicable.

Additional Information

  • Reliability: TCP is a connection-oriented protocol. Before data transmission, a connection is established between the sender and receiver by allocating resources and defining the path.
  • Three-Way Handshake: TCP uses a three-way handshake mechanism to establish the connection. This ensures that both sender and receiver are ready for communication.
  • Resource Allocation: During the connection establishment, the path from source to destination is determined, and resources are allocated to ensure smooth and reliable data transmission.

Hence, the correct answer is: option 1) up to destination is allocated before the transmission of message begins

Question 112

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

What is the output of the following code ?

String [ ] s = new String[ 3 ];

s [ 0 ] = new String(“zero”);

s [ 1 ] = new String(“one”);

s [ 2 ] = new String(“two”);

s [ 1 ] = s [ 2 ];

s [ 0 ] = s [ 1 ];

s [ 2 ] = s [ 0 ];

for(int i = 0; i < s.length; i++) {

System.out.print(s[i] + “ ’’);

}

  1. AOption (a)

    zero one two

  2. BOption (b)

    one two zero

  3. COption (c)

    two two two

  4. DOption (d)

    two one zero

View answer & explanation

Correct answer

Answer: (c)C.

two two two

Why this answer is correct

The correct answer is : option 3

Key Points

In Java, arrays of objects (like String[]) store references to the objects. So when you assign one element to another, you're copying the reference, not the actual object.

Code Breakdown:

String[] s = new String[3];

s[0] = new String("zero"); // s[0] → "zero" s[1] = new String("one"); // s[1] → "one" s[2] = new String("two"); // s[2] → "two"

s[1] = s[2]; // s[1] → "two" s[0] = s[1]; // s[0] → "two" s[2] = s[0]; // s[2] → "two"

Final Values of Array:

  • s[0] = "two"
  • s[1] = "two"
  • s[2] = "two"

Loop Output:

System.out.print(s[i] + " "); // for i = 0 to 2

→ Output: two two two

Correct Answer: Option 3) two two two ✅

Question 113

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

Encryption and decryption are functions of the _________ layer.

  1. AOption (a)

    Transport 

  2. BOption (b)

    Session

  3. COption (c)

    Application

  4. DOption (d)

    Presentation

View answer & explanation

Correct answer

Answer: (d)D.

Presentation

Why this answer is correct

The correct answer is Presentation

Key Points

  • Encryption and decryption: ✅ These processes are functions of the Presentation layer in the OSI model. This layer is responsible for translating, encrypting, and compressing data to ensure secure and efficient communication between devices.
  • Transport: ❌ The Transport layer is responsible for end-to-end communication, error detection, and flow control, but it does not handle encryption and decryption.
  • Session: ❌ The Session layer manages sessions between applications, including establishing, maintaining, and terminating connections, but it is not responsible for encryption and decryption.
  • Application: ❌ The Application layer provides services for end-user applications but relies on lower layers (like Presentation) for encryption and decryption functions.

Additional Information

  • Role of the Presentation layer: The Presentation layer converts data into a format that is understandable by the receiving application, ensuring data integrity and security through encryption and decryption.
  • Example: SSL (Secure Socket Layer) and TLS (Transport Layer Security) protocols often operate at the Presentation layer to encrypt data transmitted over a network.

Hence, the correct answer is: option 4) Presentation

Question 114

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

A constructor

i) must have the same name as the class it is declared within

ii) is used to initialize objects

iii) may be declared private

  1. AOption (a)

    i), ii) & iii) are true

  2. BOption (b)

    i) & ii) are true 

  3. COption (c)

    i) is true

  4. DOption (d)

    all are false

View answer & explanation

Correct answer

Answer: (a)A.

i), ii) & iii) are true

Why this answer is correct

The correct answer is option 1

Key Points

  • Constructors are special member functions in a class that are automatically called when an object is created. They are primarily used to initialize objects.
  • Statement i: ✅ A constructor must have the same name as the class it is declared within. This is a fundamental rule in object-oriented programming (OOP).
  • Statement ii: ✅ A constructor is used to initialize objects. For example, it can set default values for class attributes.
  • Statement iii: ✅ A constructor may be declared private. This is often done in the Singleton design pattern to restrict object creation outside the class.

Additional Information

  • Constructor Characteristics:
  • Constructors do not have a return type, not even void.
  • They are automatically invoked when an object is created.
  • Constructors can be overloaded, meaning there can be multiple constructors with different parameter lists.
  • Private Constructor: Declaring a constructor as private is a common way to implement the Singleton design pattern, which ensures that only one instance of a class is created.

Hence, the correct answer is: option 1) i), ii) & iii) are true

Question 115

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

What does the “sticky bit” do ? 

  1. AOption (a)

    It prevents files from being deleted by anyone

  2. BOption (b)

    It marks files for deletion

  3. COption (c)

    It prevents files from being deleted by nonowners except root

  4. DOption (d)

    It prevents files from being deleted by nonowners including root

View answer & explanation

Correct answer

Answer: (c)C.

It prevents files from being deleted by nonowners except root

Why this answer is correct

The correct answer is It prevents files from being deleted by nonowners except root

Key Points

  • Sticky Bit: ✅ The sticky bit is a permission flag that can be set on directories to prevent files within that directory from being deleted or renamed by users who do not own the files, except for the root user. This is commonly used in shared directories like /tmp.
  • Behavior: If the sticky bit is set on a directory, only the file's owner, the directory's owner, or the root user can delete or modify the files within the directory.
  • Example: A common scenario is the /tmp directory in Linux systems. The sticky bit ensures that users cannot delete or interfere with each other's files, even though everyone can write to the directory.

Additional Information

  • Command to Set Sticky Bit: Use the chmod command with the +t option to add the sticky bit to a directory. For example:
  • chmod +t /path/to/directory
  • Command to Check Sticky Bit: You can verify the sticky bit using the ls -ld command. If the sticky bit is set, you will see a t at the end of the permissions string. For example:
  • drwxrwxrwt (The t indicates the sticky bit is enabled.)
  • Sticky Bit on Files: Historically, the sticky bit was also used on executable files to keep them in memory, but this usage is now obsolete on modern Unix/Linux systems.

Hence, the correct answer is: option 3) It prevents files from being deleted by nonowners except root

Question 116

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

__________ data communication method is used to transmit the data over a serial communication link. 

  1. AOption (a)

    Half-duplex

  2. BOption (b)

    Full-duplex

  3. COption (c)

    Both (A) and (B)

  4. DOption (d)

    None of the above

View answer & explanation

Correct answer

Answer: (c)C.

Both (A) and (B)

Why this answer is correct

The correct answer is Both (A) and (B).

Key Points

  • Serial communication transmits data one bit at a time over a communication link.
  • It can operate in different transmission modes depending on the direction of data flow.
  • Half-duplex mode allows communication in both directions, but not simultaneously.
  • Full-duplex mode allows communication in both directions simultaneously.
  • Therefore, both Half-duplex and Full-duplex methods are used in serial communication.

Additional Information

  • Transmission Modes:
  • Simplex: Data flows in only one direction.
  • Half-duplex: Data flows in both directions, but one direction at a time.

Example: Walkie-talkie.

  • Full-duplex: Data flows in both directions simultaneously.

Example: Telephone communication.

  • Examples of Serial Communication Interfaces:
  • RS-232
  • USB
  • I²C
  • SPI
  • UART
  • Important Points:
  • Serial communication sends one bit at a time.
  • Both half-duplex and full-duplex are valid modes of serial communication.
  • Thus, the correct answer is Option 3: Both (A) and (B).

Question 117

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

The value of a variable is retained across the function calls in ________ storage class.

  1. AOption (a)

    auto

  2. BOption (b)

    static

  3. COption (c)

    register

  4. DOption (d)

    It is not possible

View answer & explanation

Correct answer

Answer: (b)B.

static

Why this answer is correct

The correct answer is static

Key Points

  • Static Storage Class: ✅ Variables declared with the static storage class retain their value between function calls. This means that the variable is initialized only once, and its value is preserved across multiple calls to the same function.
  • Auto Storage Class: ❌ The auto storage class is the default for local variables, and their lifetime is limited to the scope of the function in which they are defined. Their value is not retained between function calls.
  • Register Storage Class: ❌ The register storage class is used to declare variables that should be stored in CPU registers for faster access. Like auto, their value is not retained between function calls.
  • It is not possible: ❌ It is indeed possible to retain the value of a variable across function calls by using the static storage class.

Additional Information

  • Initialization: A static variable is initialized only once. If not explicitly initialized, it is automatically initialized to zero.
  • Scope: The scope of a static variable is limited to the function or file in which it is defined, but its lifetime extends until the program terminates.
  • Example: void exampleFunction() { static int counter = 0; // Static variable counter++; printf("Counter: %d\n", counter); }

int main() { exampleFunction(); // Output: Counter: 1 exampleFunction(); // Output: Counter: 2 exampleFunction(); // Output: Counter: 3 return 0; }

Hence, the correct answer is: option 2) static

Question 118

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

Loss of data integrity means that the

  1. AOption (a)

    Data and system cannot be accessed by the users

  2. BOption (b)

    Invalid and corrupted data has been granted 

  3. COption (c)

    Loss of protecting or maintaining secrecy over critical data of the organization

  4. DOption (d)

    Loss of protecting data from individuals

View answer & explanation

Correct answer

Answer: (b)B.

Invalid and corrupted data has been granted 

Why this answer is correct

The correct answer is Option 2

Key Points

  • Loss of data integrity: This refers to a situation where data becomes invalid, inconsistent, or corrupted. It means that the data stored in the system no longer maintains its accuracy, reliability, or consistency.
  • Explanation: When data integrity is compromised, it leads to invalid or corrupted data being stored or accessed. This can occur due to hardware failures, software bugs, unauthorized modifications, or malicious attacks.
  • Option 1 (Data and system cannot be accessed by the users): ❌ This describes a situation of loss of system availability, not data integrity.
  • Option 2 (Invalid and corrupted data has been granted): ✅ This correctly describes the loss of data integrity, where the data becomes invalid or corrupted.
  • Option 3 (Loss of protecting or maintaining secrecy over critical data of the organization): ❌ This describes a loss of confidentiality, not data integrity.
  • Option 4 (Loss of protecting data from individuals): ❌ This is a vague statement and does not directly relate to data integrity.

Additional Information

  • Data Integrity Importance: Data integrity ensures that the data remains accurate, consistent, and reliable during its entire lifecycle.
  • Prevention: To prevent loss of data integrity, organizations implement measures like data validation, encryption, regular backups, and auditing.

Hence, the correct answer is: Option 2

Question 119

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

What will be the output of the following code segment ?

int fn (int a [ ] , int n, int target) {

if (n < 0)

return -1;

else if (target == a[n]) 

return n; 

return fn(a, n-1, target); }

main ( ) {

int a [ 10 ] = {85, 4, 23, 57, 10, 24, 81, 78, 92, 16} ;

printf (“%d”, fn (a, 10, 92)) ;

}

  1. AOption (a)

    -1

  2. BOption (b)

    7

  3. COption (c)

    8

  4. DOption (d)

    9

View answer & explanation

Correct answer

Answer: (c)C.

8

Why this answer is correct

The correct answer is : option 3

Key Points

This function fn() recursively searches for a target value in an array a[] from the end towards the beginning. It returns the index of the element if found, or -1 if not found.

Code:

int fn (int a[], int n, int target) { if (n < 0) return -1; else if (target == a[n]) return n; return fn(a, n-1, target); }

int main() { int a[10] = {85, 4, 23, 57, 10, 24, 81, 78, 92, 16}; printf("%d", fn(a, 10, 92)); }

Explanation:

  • The array a[] contains 10 elements (index 0 to 9).
  • fn(a, 10, 92) is called.
  • Array indexing is 0-based, so a[10] is out of bounds.
  • However, the recursive call will first check a[10], then a[9], a[8], etc.
  • In C, using a[10] is undefined behavior, but assuming the intent was to search from index 9:

Correct usage: Call fn(a, 9, 92) instead.

a[9] = 16 (≠ 92) a[8] = 92 (✓ match!) → return 8

Final Output: 8

Correct Answer: Option 3) 8 ✅

Question 120

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

Which of the statement(s) in the following code segment will result in a syntax error ?

char a [ ] = “this”, b [ ] = “this”; // Line 1

while (*a != ‘\0’ && *b != ‘\0’) { // Line 2

if (*a != *b)  // Line 3

printf(“Not same”);  // Line 4

++a ; // Line 5

++b ; // Line 6

}

if (*a == ‘\0’ && *b == ‘\0’) // Line 7

printf(“Same”); // Line 8

  1. AOption (a)

    All the lines

  2. BOption (b)

    Line 1, Line 2 and Line 3

  3. COption (c)

    Line 5 only

  4. DOption (d)

    Line 5 and Line 6

View answer & explanation

Correct answer

Answer: (d)D.

Line 5 and Line 6

Why this answer is correct

The correct answer is : option 4

Key Points

In C, char a[] = "this" declares a character array, while char *a = "this" declares a pointer to a string literal. Array names are non-modifiable l-values and cannot be incremented like pointers.

Code Analysis Line-by-Line:

Line 1: char a[] = "this", b[] = "this"; ✅ Valid. Two character arrays initialized with string literals.

Line 2: while (*a != '\0' && *b != '\0') { ✅ Valid. Dereferencing characters from arrays.

Line 3: if (*a != *b) ✅ Valid. Compares the characters pointed to by a and b.

Line 4: printf("Not same"); ✅ Valid. Standard output statement.

Line 5: ++a; ❌ Invalid. a is an array, not a pointer, so it cannot be incremented.

Line 6: ++b; ❌ Invalid. Same reason as Line 5.

Line 7: if (*a == '\0' && *b == '\0') ✅ Valid. End-of-string check.

Line 8: printf("Same"); ✅ Valid. Prints final result.

Reason for Syntax Error:

In Line 5 and Line 6, you are attempting to increment an array variable (++a and ++b), which is not allowed in C. Array names represent constant memory addresses and are not modifiable.

To Fix: Declare them as pointers:

char *a = "this", *b = "this";

Correct Answer: Option 4) Line 5 and Line 6 ✅