Computer Knowledge

Programming Output Evaluation

1,721 Questions

Programming output evaluation tests the ability to trace code execution in languages like C, Java, and SAS. It focuses on arrays, loops, pointers, and data type conversions. These technical questions are standard in computer knowledge sections for IT officer and bank exams.

Java string bufferC language pointersLoop execution outputsData type conversionsMacro variable evaluation

Programming Output Evaluation Questions

Multiple choice technology
  1. It will not compile because the

  2. "Equal A" is the only thing that is printed

  3. "Equal B" is the only thing that is printed

  4. Both "Equal A" and

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The == operator compares object references, not content. Since new String("Computer") creates a distinct String object in memory, s == "Computer" is false (they point to different objects). The equals() method compares actual string values, so s.equals("Computer") is true, printing "Equal B".

Multiple choice technology
  1. (5, 3) (5, 3) (5, 3)

  2. (5, 3) (3, 5) (5, 3)

  3. (5, 3) (3, 5) (3, 5)

  4. (3, 3) (3, 5) (3, 5)

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Java passes primitive parameters by value, so switchCoords receives copies of x and y (values 5 and 3). Inside switchCoords, the swap changes only these local copies: temp=5, x becomes 3, y becomes 5, printing "(3, 5)". After the method returns, myMethod's original x and y remain unchanged at 5 and 3, so it prints "(5, 3)".

Multiple choice technology
  1. Returns the index of the highest

  2. Returns true/false if there are any elements that repeat in the array

  3. Returns how many even numbers are in the array

  4. Returns the highest element in the array

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The ternary operator x = x < arr[i] ? arr[i] : x compares current x with each array element. If arr[i] is larger than x, x becomes arr[i]; otherwise x stays the same. After iterating through all elements, x holds the maximum value found in the array.

Multiple choice technology
  1. 1.// Looks like a comment

  2. 2.The statement results in a compilation error

  3. 3.Looks like a comment

  4. 4.No output is displayed

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In Java, text inside double quotes is always a String literal, regardless of its content. The compiler does not treat // inside quotes as comments. The statement prints the literal string // Looks like a comment. There is no compilation error because the syntax is valid.

Multiple choice technology
  1. Compile error

  2. amitPoddar o

  3. amitPoddar i

  4. amit i

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Strings in Java are immutable - s1.concat() returns a new String but doesn't modify s1. s1 remains amit. s2 becomes aiit after replacing m with i. s1+s2 is amitaiit, and charAt(5) is i (0-indexed: a=0, m=1, i=2, t=3, a=4, i=5). So output is amit i.

Multiple choice technology programming languages
  1. It will not compile.

  2. It will print out: i=9.

  3. It will print out: i=10.

  4. It will loop indefinitely

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The function increment accepts its parameter by value, which means it only increments a local copy of the variable inside the function. Because the global loop variable i in the main function is never updated, the loop runs indefinitely.

Multiple choice technology programming languages
  1. efg

  2. cdefg

  3. fg

  4. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

To solve this question, the user needs to understand the concept of pointers in C programming. In this case, ptr is a pointer variable that points to the first character of the myString array. The statement ptr += 5 increments the pointer by 5, so that it now points to the sixth character in the array.

Option A is incorrect because ptr is pointing to the sixth character in the array, not the third.

Option B is incorrect because ptr is pointing to the sixth character in the array, not the first.

Option C is correct because ptr is pointing to the sixth character in the array, which is "f", and continues to the end of the string, "g". Therefore, the string that ptr points to is "fg".

Option D is incorrect because an answer was provided above.

Therefore, the answer is: C. fg

Multiple choice technology programming languages
  1. y = LLO

  2. y = LO

  3. y = ELLO

  4. y = HELLO

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The function increments the pointer by 3 characters. 'HELLO' + 3 points to 'LO' (the 4th character, index 3). Pointer arithmetic moves forward by 3 positions, so ptr goes from 'H' to 'L'. printf then prints 'LO'. Option B is correct. Options A ('LLO') would be +2, C ('ELLO') would be +1, D would be no pointer change.

Multiple choice technology programming languages
  1. 12

  2. 10

  3. 11

  4. 6

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Evaluating the expression: x++ is post-increment (use 5, then x becomes 6), --y is pre-decrement (y becomes -11), so the expression is 5 - (-11 * 2 / 4) = 5 - (-22/4) = 5 - (-5) = 10. In integer division, -22/4 = -5 (truncates toward zero). Final result: z = 10, x = 6, y = -11. Option B is correct.

Multiple choice technology programming languages
  1. The class compiles and runs, but does not print anything

  2. The number 2 gets printed with AssertionError

  3. The number 3 gets printed with AssertionError

  4. compile error

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The code compiles and runs without printing anything because assertions are disabled by default in Java. The nested loops iterate i=2,3 and j=2,3, checking if i

Multiple choice technology programming languages
  1. Compile with error

  2. 10

  3. 12

  4. Runtime Exception

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

All variables declared inside interfaces are implicitly public, static, and final. Attempting to reassign a value to TestInf.i (TestInf.i = 12) causes a compile-time error because it is a constant.

Multiple choice technology programming languages
  1. Compile with error

  2. 5

  3. 0

  4. Runtime Exception

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The variable 'a' is defined inside a static initialization block, making its scope local to that block. Attempting to access 'a' in the main method causes a compilation error because it is unresolved.

Multiple choice technology programming languages
  1. r1 r4 pre b1 b2 r3 r2 post

  2. r1 r4 pre b1 b2 post

  3. r1 r4 pre b1 b2 post r3 r2

  4. pre r1 r4 b1 b2 r2 r3 post

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

To understand the output of the given code, the user needs to know about the order of initialization of static and non-static blocks, constructors, and the concept of inheritance.

When the main method is executed, the following sequence of events will occur:

  1. The static block of class B will be executed first. It will print "r1 r4".

  2. The static block of class C will not be executed because it is not defined.

  3. The print statement inside the main method will execute and print "pre".

  4. A new object of class C is created using the default constructor.

  5. Since class C extends class B, the constructor of class B will be called first.

  6. Before the constructor of class B is called, the non-static block of class A will be executed. It will print "b1".

  7. The constructor of class B will be executed next. It will print "b2" and "r2".

  8. Before the constructor of class C is called, the non-static block of class B will be executed. It will print "r3".

  9. The constructor of class C will be executed last. It will not print anything.

  10. After the constructor of class C is called, the print statement inside the main method will execute and print "post".

Therefore, the output will be:

The Answer is: A) r1 r4 pre b1 b2 r3 r2 post

Multiple choice technology programming languages
  1. true

  2. false

  3. Compile Error

  4. Runtime Exception

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The code prints true because Integer.equals(Object) performs value comparison after auto-boxing the primitive int 34 to an Integer wrapper, and their primitive integer values are equal.

Multiple choice technology programming languages
  1. one

  2. two

  3. Compile error - char can't be permitted in switch statement

  4. Compile error - Illegal modifier for the class Test; only public, abstract & final are permitted

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The code has a compilation error: 'static' is not a valid modifier for a top-level class in Java - only public, abstract, and final are permitted. Option C is incorrect because chars ARE allowed in switch statements. Options A and B are irrelevant since compilation fails. The question tests Java class declaration rules.