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
  1. The condition in the for loop is must.

  2. The two semicolons should be dropped.

  3. The for loop should be replaced by a while loop.

  4. No error

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

The for loop syntax 'for(;;)' is valid C++ for creating an infinite loop - all three parts (initialization, condition, increment) are optional. The loop continues until the break statement executes when a exceeds 10. The code will print 1 through 10. Option D correctly states there is 'No error'. The loop works as written, incrementing a and breaking when a > 10. Note: The header has 'iostream.h' which is pre-standard C++; modern C++ uses .

Multiple choice
  1. This code finds the summation of the numbers from 5 to 15.

  2. This code finds the summation of 10 numbers.

  3. This code prints multipliers of 3 (from 3 to 15).

  4. This code finds the summation of the numbers from 3 to 15.

  5. There is error in the code.

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

This is the correct meaning of the given code.

Multiple choice
  1. A new color will be created.

  2. runtime Exception

  3. Parameters are not enough

  4. Compile time error : cannot find method color

  5. Compile time error : Color is Abstract cannot xreate an object.

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

This is the correct answer because color constructor creates a new color but it takes parameters in the range 0-255. But here the value passed is 284 (in first parameter). So, a runtime exception named “IllegalArgumentException” will be thrown by the JVM. 

Multiple choice
  1. Use of printf in class A

  2. C++ use cout<< operator to display the text on screen.

  3. Function definition can always be done outside the class.

  4. Function calling can be done by using the name of the function.

  5. Both (1) and (2)

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

Options (1) and (2) correctly explain the reason.

Multiple choice
  1. Runtime error

  2. Compiler error

  3. Linker error

  4. Syntax error

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

The code has a typo: 'void mail()' instead of 'void main()'. This creates a linker error because the linker looks for the main() function as the program entry point but can't find it. The program compiles successfully but fails during linking. This is a common error that occurs when the required main() function is missing or misspelled, preventing the program from being properly linked into an executable.

Multiple choice
  1. -330,150

  2. 330, -150

  3. -150, -330

  4. 6, 30

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

Tracing the function: initially a=6, b=30. After a=a*b: a=180. After b=b-a: b=30-180=-150. After a=a-b: a=180-(-150)=330. Since parameters are passed by reference, main's variables are modified. The final output is '330, -150'. The function effectively swaps and scales values through arithmetic operations.

Multiple choice
  1. now = 5, next = 5

  2. now = 40, next = 5

  3. now = 10, next =10

  4. now = 40, next = 10

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

The inner value() function has static int j=40, so it prints 40. The outer value() function has static int j=5. When value() calls value(), the inner function's j (40) is printed first, then the outer's j (5). The global j=10 is shadowed by both function-local static variables.

Multiple choice
  1. int digits[5]={1,2,3,4,5};

  2. float num[10];

  3. char color[3]={R,G,B};

  4. static float x[3]={2.5, 6.2, 7.8};

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

Character array elements must be character literals enclosed in single quotes. Option C uses 'R,G,B' without quotes, which is incorrect syntax - it would be interpreted as variables, not characters. The correct syntax would be char color[3]={'R','G','B'};

Multiple choice
  1. a=2 a=2 a=2

  2. a=2 a=6 a=2

  3. a=2 a=6 a=6

  4. none of these

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

C passes arguments by value, so when 'modify(a)' is called, only the value of a (which is 2) is copied to the function. Inside modify(), the parameter a becomes 6 (2×3), but this change is local to the function and doesn't affect the original variable in main(). The printf statements show: a=2 (first), a=6 (inside modify), a=2 (back in main).