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 web technology
  1. somerar is 15

  2. somerar is 16

  3. somerar is 1

  4. error in code

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

To solve this question, the user needs to understand the concept of global variables and function in PHP. The script defines a global variable named \$somevar with a value of 15, and a function named addit() that increments the value of \$somevar by one and then outputs its new value. The function explicitly states the variable is global using the global keyword.

When the addit() function is called, it will first increment the value of $somevar by one, resulting in a value of 16. Then, the function will output the string "somerar is 16" using the echo statement.

Therefore, the correct answer is:

The Answer is: B. somerar is 16

Multiple choice technology programming languages
  1. The program has a syntax error.

  2. The program has a runtime error.

  3. The program runs fine, but displays nothing.

  4. The program runs fine and displays It is even!.

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

The expression even = true is an assignment operator, not a comparison operator (==). It assigns true to even and evaluates to true, causing the if statement block to execute and print It is even!.

Multiple choice technology programming languages
  1. The program cannot compile because you cannot have the print statement in a non-void method

  2. The program cannot compile because the compiler cannot determine which max method should be invoked

  3. The program runs and prints 2 followed by "max(int, double)" is invoked.

  4. The program runs and prints 2 followed by "max(double, int)" is invoked.

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

The call max(1, 2) passes two int literals. Java's overload resolution requires finding the most specific method. The two overloaded methods are max(int, double) and max(double, int). To call either, one int must be promoted to double. Both conversions are equally applicable, creating ambiguity. The compiler cannot determine which method to invoke, so compilation fails.

Multiple choice technology programming languages
  1. 5

  2. 6

  3. 7

  4. 8

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

The do-while loop executes at least once. Iteration 1: item becomes 1, sum becomes 1. Iteration 2: item becomes 2, sum becomes 3. Iteration 3: item becomes 3, sum becomes 6. Now sum > 4, so break executes. Loop terminates. Final sum is 6.

Multiple choice technology programming languages
  1. 0x22ff74

  2. 0x22ff70

  3. 0x22ff73

  4. Compiler error

  5. 19

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

Pointer arithmetic scales by the size of the pointed-to type. On a 32-bit system, int is typically 4 bytes. When you subtract 1 from an int pointer, it decreases by 4 bytes (not 1 byte). So if ptr points to 0x22ff74, ptr-1 points to 0x22ff70. This is a fundamental property of pointer arithmetic in C/C++.

Multiple choice technology programming languages
  1. vp=&f;

  2. c=(char*)&i;

  3. c=vp;

  4. *i++;

  5. f++;

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

In C++, assigning a void* to a char* without an explicit cast is not allowed. While this is valid in C (where void* can be implicitly converted to any other pointer type), C++ requires an explicit cast: c = (char*)vp; or c = static_cast(vp);. The other assignments are valid - void* can receive any pointer, and casts between pointer types are allowed.

Multiple choice technology programming languages
  1. 3,7

  2. 3,5,7

  3. index Outofbound exception

  4. Compilation fails

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

The code fails to compile because Java generics cannot use primitive types. 'List' and 'ArrayList()' are invalid - you must use wrapper types like 'List' and 'ArrayList'. The compiler will reject this code at the declaration line, so no execution occurs.

Multiple choice technology programming languages
  1. 3,7

  2. 3,5,7

  3. index Outofbound exception

  4. Compilation fails

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

Java generics do not support primitive types like int; they require reference types like Integer. Therefore, declaring List causes a compilation failure. Additionally, iterating over myList using a String loop variable would also fail compilation.

Multiple choice technology programming languages
  1. A

  2. ABC

  3. comilation fails

  4. AB

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

Compilation fails for two reasons: (1) Switch statements on Boolean wrapper types are not supported in Java - only int-compatible types, enums, and String (Java 7+) are allowed. (2) The case syntax case(true) with parentheses is incorrect even for valid switch types; cases must use constant values without parentheses.

Multiple choice technology programming languages
  1. The compiler interprets the bytecode in the Java class file

  2. The Java Virtual Machine (JVM) interprets the bytecode in the Java class file

  3. The JVM interprets the native machine code

  4. The JVM translates compiled bytecode to machine code

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

The Java platform uses the JVM to execute bytecode. The JVM can either interpret the bytecode directly or use JIT compilation to translate it to native machine code. The compiler's job ends after creating the class file - it doesn't execute code.

Multiple choice technology programming languages
  1. 15,15

  2. 12,12

  3. 12,15

  4. 15,12

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

StringBuffer is initialized with capacity 15, but capacity is the allocated space, not the actual content length. The string "Hello World!" contains 12 characters (including space and exclamation). The length() method returns 12 (actual characters), while capacity() returns 15 (allocated space). Therefore, the output is "12,15".

Multiple choice technology programming languages
  1. True

  2. False

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

The expression compares a string literal and a new string object using reference equality (==) which returns false, and content equality (equals) which returns true. The XOR operator (^) evaluates false ^ true as true because the operands differ.