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 programming languages
  1. Size of c: some value Addr of c:some address

  2. Size of c: some value Addr of c:some value

  3. Size of c: some address Addr of c:some address

  4. Compilation error

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

In modern C standards, defining main() without an explicit return type (such as int) results in a compilation error. Distractors are incorrect because the compiler will fail to build the program before it can execute and output any size or address values.

Multiple choice technology programming languages
  1. -

  2. -c

  3. -c2

  4. -2c

  5. -c22b

  6. -2c2b

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

s starts as "-". s1() calls s2(). s2() calls s3() which throws Exception immediately. The statements s += "2" in s2() never execute. s1() catches the exception and executes s += "c". Final value: "-c".

Multiple choice technology programming languages
  1. for(int y : x) {

  2. for(x : int y) {

  3. int y = 0; for(y : x) {

  4. for(int y=0, z=0; z<x.length; z++) { y = x[z];

  5. for(int y=0, int z=0; z<x.length; z++) { y = x[z];

  6. int y = 0; for(int z=0; z<x.length; z++) { y = x[z];

Reveal answer Fill a bubble to check yourself
A,D,F Correct answer
Explanation

A is correct for-each syntax. D is valid - declares y=0, z=0 then iterates. F is valid - y declared outside, z declared in loop. B has wrong order. C declares y in initialization which isn't allowed. E incorrectly declares int z in initialization.

Multiple choice technology programming languages
  1. 1 3 9

  2. 5 5 7 7

  3. 1 3 3 9 9

  4. 1 1 3 3 9 9

  5. 1 1 1 3 3 3 9 9 9

  6. Compilation fails

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

For x=1,3: prints twice each. For x=5,7: continue outer loop skips them. For x=9: prints twice. The inner loop prints x on j=0, breaks on j=1. Output: 1 1 3 3 9 9 (12 characters with spaces).

Multiple choice technology programming languages
  1. 0 1 2 3

  2. 1 1 1 3 3

  3. 0 1 1 1 2 3 3

  4. 1 1 1 3 3 4 4 4

  5. 0 1 1 1 2 3 3 4 4 4

  6. compilation fails

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

j=0: prints 0, breaks inner. j=1: prints 1 1 1 (no break triggered). j=2: prints 2, breaks inner. j=3: prints 3 3 then breaks foreach. Output: 0 1 1 1 2 3 3.

Multiple choice technology programming languages
  1. t t1

  2. t1 t

  3. t t

  4. Compilation succeed but Runtime Exception

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

Java thread priorities must be between 1 (MIN_PRIORITY) and 10 (MAX_PRIORITY). The code attempts to set t1's priority to -3, which violates this constraint. This causes an IllegalArgumentException at runtime. The code compiles successfully but crashes during execution.

Multiple choice technology programming languages
  1. good

  2. null

  3. Compilation fails with an error at line 5

  4. Compilation succeed but Runtime Exception

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

The Thread object 't' is named 'good' before starting. When the thread executes, its run() method calls Thread.currentThread().getName(), which returns 'good'. The main thread creates and starts 't' but doesn't print anything itself.

Multiple choice technology programming languages
  1. 59

  2. Compile time error, because you have to do int total = ((Integer)(list.get(0))).intValue();

  3. Compile time error, because can't add primitive type in List.

  4. Compile Properly but Runtime Exception

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

Java's compiler handles autoboxing and unboxing automatically. The primitive int value 59 is autoboxed into an Integer when added to the list, and then automatically unboxed back to an int when retrieved using list.get(0), making the code correct and printing 59 without errors.

Multiple choice technology programming languages
  1. 0

  2. Compile with error

  3. null

  4. NullPointerException

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

The code attempts to unbox a null Integer reference to a primitive int. Unboxing involves calling i.intValue(), which throws NullPointerException when i is null. The exception occurs before any output is produced.

Multiple choice technology programming languages
  1. Value of a is 7

  2. Compile Error - not able to access private member.

  3. Runtime Exception

  4. Value of a is 8

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

In Java, a non-static inner class holds an implicit reference to its enclosing outer class instance. Consequently, inner classes can directly access all members of the outer class, including those declared with private access modifiers, allowing the display of a as 7.

Multiple choice technology programming languages
  1. Compile with error

  2. USA

  3. UK

  4. Runtime Exception

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

Java uses method signature (name + parameter types) to distinguish methods. Return type alone cannot differentiate overloaded methods. Two getCountryName() methods with identical parameter lists (both empty) are ambiguous, causing a compilation error regardless of return types.

Multiple choice technology programming languages
  1. true

  2. compile error

  3. false

  4. b

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

The regex 'a*b' matches zero or more 'a' characters followed by 'b'. The input string 'b' contains zero 'a's followed by 'b', which satisfies this pattern. The matches() method returns true when the entire input matches the pattern.

Multiple choice technology programming languages
  1. 1 2 red blue

  2. Compile Error - because Scanner is not defind in java.

  3. 1 fish 2 fish red fish blue fish

  4. 1 fish 2 fish red blue fish

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

To solve this question, the user needs to understand how the Scanner class works in Java and how the useDelimiter() method works.

The useDelimiter() method sets the delimiter pattern for the Scanner object to use when breaking down input into tokens. In this case, the delimiter pattern is set to "\s*fish\s*", which means that the Scanner object will split the input string whenever it encounters the word "fish" surrounded by any number of whitespace characters.

The code then uses the nextInt() and next() methods of the Scanner object to retrieve the tokens that were split from the input string.

Let's go through each option to determine the correct answer:

A. 1 2 red blue: This option is correct. The first call to nextInt() retrieves the integer "1" that comes before the first occurrence of "fish". The second call to nextInt() retrieves the integer "2" that comes after the first occurrence of "fish". The first call to next() retrieves the word "red", and the second call to next() retrieves the word "blue".

B. Compile Error - because Scanner is not defined in java.: This option is incorrect. The Scanner class is defined in Java, so this code will not produce a compile error due to the use of Scanner.

C. 1 fish 2 fish red fish blue fish: This option is incorrect. The code does not print out the entire input string, but rather it retrieves specific tokens from the input string using the nextInt() and next() methods.

D. 1 fish 2 fish red blue fish: This option is incorrect. The second call to nextInt() retrieves the integer "2", which comes after the first occurrence of "fish". The first call to next() retrieves the word "red", and the second call to next() retrieves the word "blue".

Therefore, the correct answer is:

The Answer is: A. 1 2 red blue