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. class aClass{public:int x;};

  2. /* A comment */

  3. char x=12;

  4. None of the Above

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

C does not support classes or the 'class' keyword - these are C++ OOP features. Options B and C are valid C syntax (comments and char initialization). Option A uses C++ class syntax which is invalid in C.

Multiple choice technology programming languages
  1. ab

  2. abc

  3. c

  4. none of the above

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

In the loop initialization, printf("a") executes and prints 'a'. Next, the condition printf("b") executes, prints 'b', and returns a non-zero value (true). The loop body then runs, executing break immediately. The loop terminates before the increment step, resulting in 'ab'.

Multiple choice technology programming languages
  1. 0

  2. 1

  3. compile error

  4. 10

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

Pointer p is assigned address of i. Then p++ increments p by one integer (4 bytes on most systems). The expression (p - &i) calculates the offset between the new pointer address and original address, which is 1 integer - not 1 byte. The difference is measured in the pointer's data type units, so it equals 1.

Multiple choice technology programming languages
  1. 0

  2. 1

  3. compile error

  4. 10

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

A long pointer on most systems is 8 bytes (or 4, depending on architecture), while int is 4 bytes. When you assign &i (int pointer) to long* pointer p, there's a type mismatch. After p++, the difference p - &i is calculated as pointer arithmetic: p advances by sizeof(long) bytes, &i is the original address. The difference is the number of long-sized steps between them, which is 1.

Multiple choice technology programming languages
  1. Reboot the Machine

  2. Disable the print screen key

  3. Change the default screen color

  4. puts Capslock on

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

In DOS/BIOS environments, memory address 0x417 (segment 0x0000, offset 0x0417) is the BIOS keyboard data area that stores the keyboard shift status byte. The bits in this byte control toggle keys like CapsLock, NumLock, ScrollLock. Setting bit 6 (value 64) turns on CapsLock. This is a direct hardware manipulation through memory-mapped I/O.

Multiple choice technology programming languages
  1. 5

  2. garbage value

  3. compile error

  4. 2

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

The expression ++(a+1) breaks down as: (a+1) points to the second row {4,5,6}, (a+1) gives the address of the first element of that row, *(a+1) dereferences to get the value 4, and ++ pre-increments it to 5 before printf uses it. The array is modified, and 5 is printed.

Multiple choice technology programming languages
  1. Compilation fails due to error at line 1,2,3,4

  2. Compilation fails due to error at line 3,4

  3. Compiles fine and exception is thrown at runtime.

  4. Compiles fine and prints "check check 20.01"

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

To solve this question, the user needs to understand the concepts of Hashtable and data types in Java.

The code creates a Hashtable named ht, which maps keys to values. It puts three key-value pairs into the Hashtable:

  • "chec" is mapped to "check"
  • 1000 is mapped to "check"
  • "check" is mapped to 20.01

The code then retrieves the values corresponding to three keys and prints them out.

Now let's go through each option and explain why it is right or wrong:

Option A: Compilation fails due to error at line 1,2,3,4 This option is incorrect. There are no compilation errors in this code.

Option B: Compilation fails due to error at line 3,4 This option is incorrect. There are no compilation errors in this code.

Option C: Compiles fine and exception is thrown at runtime. This option is incorrect. The code compiles without errors, but no exception is thrown at runtime. The output of the code is "check check 20.01".

Option D: Compiles fine and prints "check check 20.01" This option is correct. The code compiles without errors, and when run, it prints "check check 20.01". The keys "chec" and 1000 are mapped to the value "check", while the key "check" is mapped to the value 20.01.

Therefore, the answer is: D. Compiles fine and prints "check check 20.01".

Multiple choice technology embedded technologies
  1. A) Compilation error at line 3

  2. B) Prints 23, 5, 5 and 23.

  3. C) Prints 5, 5, 5 and 23.

  4. D) Prints 23, 5, 23 and 23.

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

Line 1 performs string concatenation, yielding " 23". Line 2 adds integers, outputting 5. Line 3 adds integers first (5) then appends a string, outputting "5". Line 4 concatenates 2, an empty string, and 3, outputting "23".

Multiple choice technology programming languages
  1. A. It would fail to compile

  2. B. It would generate a run-time error on execution.

  3. C. It would execute, but ask the user to specify the directory in which to create ll.txt.

  4. D. It would execute without an error and print "hi" to a file called ll.txt

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

FileOutputStream creates the file if it doesn't exist and opens it for writing. PrintStream wraps this output stream and provides convenient methods like println. The code successfully creates ll.txt and writes hi to it. No exceptions occur because the throws Exception clause handles any IOException.