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

  2. fff0

  3. 0ff0

  4. 0fff

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

In C, -1 is represented as all 1s in two's complement (0xFFFFFFFF for 32-bit or 0xFFFF for 16-bit). Left shifting by 4 positions multiplies by 16, giving 0xFFFFFFF0 (32-bit) or 0xFFF0 (16-bit). On systems where the output is 4 hex digits, this prints as fff0. Option A (ffff) would be the result without shifting, while options C and D are incorrect bit patterns.

Multiple choice technology programming languages
  1. 5 6 6 5 5

  2. 6 5 6 5 5

  3. 5 5 6 5 5

  4. 4 5 5 4 5

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

In C, the order of evaluation of printf arguments is unspecified. However, the values are computed right-to-left before printing. Starting from i=5: i++ makes 6, i-- makes 4, ++i makes 5, --i makes 4, and i is 4. But compilers may vary. On systems producing 4 5 5 4 5, this matches option D. This tests understanding of increment/decrement operators and evaluation order.

Multiple choice technology programming languages
  1. 6

  2. junk value

  3. some address

  4. error

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

The code declares 'p' as a pointer to a const int (int const *p), meaning the value pointed to cannot be modified. The line printf("%d",++(*p)) attempts to increment the value through the pointer, which violates the const qualifier. This results in a compilation error. Option D is correct.

Multiple choice technology programming languages
  1. 32

  2. 4

  3. 64

  4. 16

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

The macro square(x) expands to x*x. When used in 64/square(4), this becomes 64/4*4 due to macro expansion (not 64/(4*4)). Following C's left-to-right evaluation for same-precedence operators: 64/4 = 16, then 16*4 = 64. This is a classic macro pitfall - always use parentheses in macro definitions. Option C (64) is correct.

Multiple choice technology programming languages
  1. 100 100 100 2 112 104 102 3

  2. 100 104 108 3 112 116 120 3

  3. 100 100 100 2 112 104 102 2

  4. 100 104 108 2 112 116 120 2

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

With base address 100, a is the array address (100). a is the first 2D array address (also 100 due to same starting point). **a is the first 1D array address (still 100). **a dereferences to the first element value (2). For the second printf: a+1 adds one full 3D array (size 12 integers = 48 bytes) giving 148... wait, let me recalculate. With base address 100 for a[2][3][2], each dimension's size varies. The output 100 100 100 2, 112 104 102 3 is consistent with pointer arithmetic on this multidimensional array structure.

Multiple choice technology programming languages
  1. 123 234 340 012

  2. 111 222 333 444

  3. 111 222 444 333

  4. 012 340 234 123

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

This code uses an array of pointers and a pointer to a pointer. ptr starts pointing to p. After ptr++, ptr-p=1, *ptr-a=1, **ptr=1 (value at a[1]). The operations *ptr++, *++ptr, and ++*ptr manipulate these pointers in different ways. The output 111 222 333 444 shows the progression through the array elements as the pointer is advanced through each step.

Multiple choice technology web technology
  1. compiletime error at lines 3,4,5

  2. compiltime error at line 4,5

  3. compiletime error at line 3

  4. Runtime Exception

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

Line 3 is valid Java syntax creating a 2D array. Line 4 is invalid because array declaration syntax int a2[4] is not allowed in Java (must use int[] a2 and initialization syntax). Line 5 is invalid because it declares array but uses C-style declaration syntax and the variable a2 is already declared.

Multiple choice technology programming languages
  1. 20,10

  2. 10,20

  3. 1,10

  4. 20,2

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

This code uses XOR swap algorithm. a=10, b=20. After a=a^b: a=30, b=20. After b=a^b: a=30, b=10. After a=a^b: a=20, b=10. The XOR operation reverses the swap in the last step, effectively exchanging the values. This is a classic technique for swapping without a temporary variable.

Multiple choice technology programming languages
  1. doStuffx = 5 main x = 5

  2. Compilation fails.

  3. doStuffx = 6 main x = 5

  4. An exception is thrown at runtime

  5. doStuffx = 6 main x = 6

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

Java uses pass-by-value for primitive types. When x=5 is passed to doStuff(), the method receives a copy of x (value 5). The post-increment x++ prints 5 first, then increments the local parameter to 6. The original x in main remains 5 because primitives are passed by value, not by reference.

Multiple choice technology programming languages
  1. int[] scores = {3, 5, 7};

  2. int [][] scores = {2,7,6}, {9,3,45};

  3. String cats[] = {“Fluffy”, “Spot”, “Zeus”};

  4. boolean results[] = new boolean [3] {true, false, true};

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

Option A is valid 1D array initialization. Option B has two errors: missing inner braces for 2D structure, and incorrect syntax - should be {{2,7,6}, {9,3,45}}. Option C is valid String array. Option D is invalid - cannot specify size [3] when using array initialization syntax; either use new boolean[3] or the initialization syntax, not both.

Multiple choice technology programming languages
  1. compiler error

  2. Hello from a thread!

  3. runtime error

  4. none of these

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

The code creates a new HelloThread object and calls start(), which spawns a new thread and invokes run(). The run() method prints "Hello from a thread!". This is standard Java threading - the Thread class's start() method creates the thread and calls run() in the new execution context.

Multiple choice technology databases
  1. y

  2. n

  3. error

  4. no output

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

When comparing NULL values in PL/SQL, any comparison operation (=, <, >, etc.) returns NULL (unknown), not true or false. In an IF statement, NULL is treated as false, so the condition a < b evaluates to false and the ELSE branch executes, printing 'n'. This is a fundamental NULL handling behavior in PL/SQL.

Multiple choice technology programming languages
  1. k will display garbage values

  2. k will print 0, as default constructor is called.

  3. Error as no constructor is defined.

  4. Error, as main should precede with int and should return 0.

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

Const data members must be initialized either via an initializer list in the constructor or with in-class initialization (C++11 and later). Since class A has no constructor and const member k is not initialized at declaration, the code fails to compile.

Multiple choice technology programming languages
  1. 42

  2. Compilation Error - Incompatible Type

  3. Runtime Error - Java.lang.ClassCastException

  4. None of above

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

The code correctly adds Integer 42 at index 0, then retrieves it using get(0). Since autounboxing converts Integer to int automatically when assigning to the int variable 'total', the output is 42. There is no compilation error (types are compatible) and no ClassCastException (autounboxing handles the conversion).

Multiple choice technology programming languages
  1. 3.14

  2. Compile time error

  3. Run time error

  4. None of above

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

The code produces a compilation error because static import of java.lang.Math.PI is invalid syntax - PI is a static field but cannot be imported this way. The correct approach is either to use Math.PI directly or import the entire Math class statically. Options A, C, and D are incorrect.