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. Num variable of Myclass is initialized to 10

  2. Run Time Error

  3. Compiler Error

  4. StackOverflow Exception

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

The code has a compiler error because variable 'c' is declared without the 'Dim' keyword. In VB.NET, all variable declarations require 'Dim', 'Public', 'Private', or similar keywords. The line 'Dim c as Myclass' is missing this keyword.

Multiple choice technology programming languages
  1. Num variable of Myclass is initialized to 10

  2. Run Time Error

  3. Compiler Error

  4. StackOverflow Exception

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

The constructor in MyClass is declared as Private, which means it cannot be accessed from outside the class. When Test.Main tries to create an instance with 'C=New Myclass(10)', the compiler detects this accessibility violation and fails before runtime.

Multiple choice technology programming languages
  1. x is greater

  2. y is greater

  3. compile error

  4. none

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

When comparing a signed integer (-2) with an unsigned integer (12), C converts the signed value to unsigned. -2 becomes a large positive number (approximately 4 billion for 32-bit int), so it is greater than 12. The output is 'x is greater'.

Multiple choice technology programming languages
  1. 7,49

  2. 7,42

  3. 7,36

  4. 7,25

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

In C, evaluating ++x * ++x (where x starts at 5) is undefined behavior. On many compilers (like GCC), both increments execute before the multiplication, making x become 7, and the multiplication evaluates to 7 * 7 = 49. Although undefined, 7 and 49 is the classic compiler output represented by the stored correct option.

Multiple choice technology programming languages
  1. 5,5

  2. 3,3

  3. 3,5

  4. Error

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

In C, the comma operator evaluates its left operand, discards the result, and returns the right operand. Thus, c = a, b; binds as (c = a), b; due to operator precedence, setting c to 3. Meanwhile, d = (a, b); evaluates the group, setting d to 5. The printed output is c = 3 and d = 5, which is matches option '3,5'.

Multiple choice technology programming languages
  1. -16

  2. fff0

  3. 0

  4. 0010

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

Shifting -1 (which is represented as all bits set, e.g., 0xffff in 16-bit) left by 4 bits yields 0xfff0. When printed as a hex value using '%x', this prints as 'fff0' (or 'fffffff0' on 32-bit systems, but 'fff0' is the intended output for a 16-bit integer context). The decimal representation -16 is wrong due to the '%x' format specifier.

Multiple choice technology programming languages
  1. O

  2. H

  3. HELLO

  4. Compilation Error

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

The code attempts to initialize a 4-element character array with a 6-character string literal (5 characters + null terminator). In C, array initialization with an oversized string literal is a compilation error because the initializer exceeds the declared array size. While some compilers might allow this as an extension with a warning, standard C requires compilation error. The program cannot execute as written due to this initialization error.

Multiple choice technology programming languages
  1. Compilation error

  2. syntax error

  3. 10 2 3 4 5 6 7 8

  4. print the address of pointer p and q

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

The code contains a syntax error because the statement *q=***a is missing a terminating semicolon. This prevents compilation. Additionally, main() lacks an explicit return type, which modern C compilers reject. Distractors are incorrect because the code cannot run to output any data or addresses.

Multiple choice technology programming languages
  1. value @c: ffffffad

  2. value @c: 0xf0ad

  3. compilation error

  4. syntax error

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

On a little-endian system (x86/x64), the 32-bit value 0xf0ad is stored in memory as bytes 0xad 0xf0 0x00 0x00 (least significant byte first). When cast to char*, the pointer addresses the first byte (0xad). When this char value (0xad = -1 as signed char) is promoted to int for printf with %x, sign extension extends it to 0xffffffffad, which printf displays as ffffffad. This demonstrates endianness and sign extension behavior.

Multiple choice technology programming languages
  1. 23

  2. Prints some address

  3. Compilation error

  4. Run time error

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

The code declares 'i' as extern but never defines it. An extern declaration tells the compiler that the variable exists elsewhere, but without a definition, the linker cannot resolve the symbol. The assignment 'i=23;' attempts to use an undefined external symbol, which causes a linkage error during compilation/linking. Every extern variable must have exactly one definition in some translation unit.

Multiple choice technology programming languages
  1. 0 0 0

  2. 0 1 0

  3. 0 0 1

  4. 0 1 1

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

The static array a[] is initialized to 0. The statement a[i]=i++ where i=0 has undefined behavior in C (modifying and reading i in same expression), but in practice: a[0] is assigned 0, then i increments to 1. The output shows a[0]=0, a[1]=0 (unchanged static value), and i=1.