Computer Knowledge

Programming Output Evaluation

1,953 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. myprog

  2. good

  3. morning

  4. Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2"

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

When Java is invoked with 'java myprog good morning', the command-line arguments array argv[] contains only [good, morning], with indices 0 and 1. Accessing argv[2] attempts to read beyond the array bounds, causing an ArrayIndexOutOfBoundsException. The program name 'myprog' is not in the argv array.

Multiple choice technology programming languages
  1. one

  2. one default

  3. one two default

  4. default

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

In Java switch statements, execution falls through to the next case when a break statement is missing. Since i=1 matches case 1, it prints 'one', then continues to case 2 printing 'two', then to default printing 'default'. Without break statements after each case, all subsequent code executes.

Multiple choice technology programming languages
  1. System.out.println(Math.floor(-4.7));

  2. System.out.println(Math.round(-4.7));

  3. System.out.println(Math.ceil(-4.7));

  4. System.out.println(Math.min(-4.7));

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

Math.ceil returns the smallest integer greater than or equal to its argument. For -4.7, ceiling gives -4.0 (since -4 is greater than -4.7). Math.floor would give -5.0, Math.round would give -5 (rounds toward positive infinity for negative numbers), and Math.min requires two arguments.

Multiple choice technology programming languages
  1. float f=2.3;

  2. char c="z";

  3. boolean b=null;

  4. int i=21;

  5. byte b=257;

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

int i=21; is a valid declaration and compiles successfully. float f=2.3; fails because 2.3 is a double literal. char c="z"; fails because double quotes are for Strings, not chars. boolean b=null; is invalid because boolean is a primitive, and byte b=257; exceeds byte's range.

Multiple choice technology programming languages
  1. error method main not correct

  2. error Can't make static reference to void a method.

  3. error array must include parameter

  4. a method must be declared with String

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

The non-static method amethod cannot be directly referenced or called from the static main method without instantiating MyClass first. The error message explicitly points out trying to make a static reference to a non-static method, whereas the other options describe unrelated issues.

Multiple choice technology programming languages
  1. float f=1.3;

  2. char c="a";

  3. int i=10;

  4. boolean b=null;

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

In Java, int i=10; is a valid assignment of an integer literal. float f=1.3; fails compilation because 1.3 is double by default and needs an 'f' suffix. char c="a"; fails because double quotes define a String, and boolean is a primitive type that cannot be assigned null.

Multiple choice technology programming languages
  1. 6

  2. 0

  3. 1

  4. 7

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

The bitwise OR operation 4 | 3 works on the binary representations: 4 is 100 and 3 is 011. OR produces 111 (binary) which is 7 in decimal. Each bit position is 1 if either operand has a 1 in that position.

Multiple choice technology embedded technologies
  1. Compilation fails.

  2. The program hangs at line 22.

  3. Out of Memory! is printed to the system console.

  4. An exception is thrown at runtime but there is no guarantee an alert will be shown to the user.

Reveal answer Fill a bubble to check yourself
D Correct answer
Multiple choice technology programming languages
  1. Execution time error

  2. Syntax error

  3. R4R:0

  4. None

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

In C++, when you initialize an integer with leading zeros like 'int a=000', the compiler interprets it as an octal (base-8) literal. However, 000 in octal equals 0 in decimal. So the program prints 'R4R:' followed by '0', giving the output 'R4R:0'. There's no syntax or execution error - the code is valid and runs correctly.

Multiple choice technology programming languages
  1. Execution time error

  2. syntax error

  3. R4R

  4. None

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

The code has a syntax error because the cout statement lacks a terminating semicolon before return 0;. Additionally, `` is an outdated header style, but the missing semicolon directly triggers a compilation syntax error, preventing successful execution or outputting of the string.

Multiple choice technology programming languages
  1. 33,123

  2. 123,33

  3. 6,6

  4. Compilation Error

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

Java evaluates arithmetic expressions from left to right. In 1+2+"3", the integers 1 and 2 are added to get 3, which is concatenated with "3" to yield "33". In "1"+2+3, the string "1" is concatenated with 2 and then 3, producing "123".

Multiple choice technology programming languages
  1. True

  2. False

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

In Java, dividing a floating-point number by zero does not throw an exception. Instead, it produces positive or negative infinity (Float.POSITIVE_INFINITY in this case). Only integer division by zero throws ArithmeticException. Therefore the statement does NOT throw an exception, making 'False' the correct answer.