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. 10

  2. 20

  3. Compilation Error

  4. RuntimeError

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

The pointer z stores the address of x. Initially x=10, then x=20 overwrites it. When *z=10 executes, it dereferences the pointer and modifies the value at address z, which is x. This changes x back to 10. The final value of x is 10.

Multiple choice technology programming languages
  1. CompilationFails

  2. Will Throw RunTime Error But Code will get Compiled

  3. Throws Linker Error

  4. All the above statements are invalid

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

The code uses sizeof(void) which is invalid in C/C++ - you cannot determine the size of void type. This causes a compilation error. Void pointers exist, but void itself is an incomplete type with no defined size. Additionally, incrementing a void pointer (ptr++) requires knowing the size of the pointed-to type, which is impossible for void* without a cast.

Multiple choice technology programming languages
  1. 5,4

  2. -4,4

  3. -5,4

  4. -4,5

  5. Compilation Error

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

The post-decrement operator a-- returns the current value (5) before decrementing a to 4. Unary minus is then applied to the returned value (5), giving -5. So num = -5, a = 4, output is "-5 4".

Multiple choice technology
  1. Compiler error

  2. FileNotFoundException thrown at line 1

  3. None of these

  4. .IOException thrown at line 2

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

FileWriter creates the file 'bb.txt' if it doesn't exist, so no FileNotFoundException occurs at line 1. However, BufferedWriter.write(int) writes a single character (the low 16 bits of the integer), not the string '1'. At line 2, w.write(1) writes a character with codepoint 1 (not printable), which is valid. The program compiles and runs without error; no exception is thrown. The correct answer is 'None of these' because the program completes successfully.

Multiple choice technology
  1. Compilation fails.

  2. finished

  3. Exception

  4. D.Arithmetic Exception

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

In Java exception handling, more specific catch blocks must come before more general ones. ArithmeticException is a subclass of Exception. The code catches the general Exception first, making the ArithmeticException block unreachable; compilation fails. If the order were reversed, the program would catch ArithmeticException, then print 'finished' after the catch block.

Multiple choice technology programming languages
  1. Prints "True"

  2. Prints nothing

  3. Prints false

  4. Error in if condition

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

The code uses assignment (=) instead of equality (==) in the if condition, so b becomes true and the condition passes. This is a common bug - the if statement evaluates the result of the assignment, which is the assigned value (true), causing 'True' to be printed.

Multiple choice technology programming languages
  1. Compile error at 2,3,4,5

  2. Compile error at 1,2,3,4,5

  3. prints 3

  4. none of the above

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

In Java, local variables inside methods cannot have access modifiers (private, protected, public). These modifiers only apply to class members (fields and methods). Lines 2, 3, and 4 attempt to declare local variables with access modifiers, which is a compile error. Line 5 uses these variables, adding to the errors. The class-level 'int i' is valid shadowed by the local 'int i' at line 1.

Multiple choice technology programming languages
  1. Prints one, two , three

  2. prints one

  3. compile time error

  4. Run time Exception

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

This switch statement lacks 'break' statements, causing fall-through execution. When i1 equals 1, case 1 matches and 'one' is printed, but execution continues through case 2 (printing 'two') and case 3 (printing 'three'). This is the default switch behavior in Java - without explicit breaks, all cases after the matching case execute sequentially.

Multiple choice technology programming languages
  1. Yes will compile

  2. no doesnot compile

  3. changes have to be made in checking the variables

  4. none

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

This line compiles successfully assuming the variables i and j are declared as compatible numeric types. The initialization, condition, and update expressions within the for-loop header follow standard Java syntax. The distractor options incorrectly claim compilation failure or suggest unnecessary changes to the loop structure.

Multiple choice technology programming languages
  1. true

  2. Compile Error

  3. false

  4. NullPointerException

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

To solve this question, the user needs to know the basics of regular expressions and the use of the Pattern and Matcher classes in Java. The given code compiles a regular expression pattern and matches it with the string "aaab". The regular expression pattern "a{3}b?c*" means that the pattern should start with three "a" characters, optionally followed by a single "b" character, and then zero or more "c" characters.

The Matcher.matches() method tries to match the entire input sequence against the pattern. If the entire input sequence matches the pattern, the method returns true; otherwise, it returns false.

In this case, the input sequence "aaab" matches the pattern "a{3}b?c*", because it starts with three "a" characters and ends with zero "c" characters. The optional "b" character is present in the input sequence, but it is not required to match the pattern.

Therefore, the output of the code will be:

The Answer is: A (true)