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. a1 == a2 is falsearr1.equals(arr2) is falseArrays.equals(a1, a2) is true

  2. a1 == a2 is truea1.equals(a2) is falseArrays.equals(arr1, arr2) is true

  3. a1 == a2 is falsearr1.equals(a2) is trueArrays.equals(a1, a2) is true

  4. a1 == a2 is truea1.equals(a2) is trueArrays.equals(a1, a2) is false

  5. a1 == a2 is truea1.equals(a2) is trueArrays.equals(a1, a2) is true

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

The first comparison between two array objects is carried out using the == operator, which compares object similarity, so it returns false here. The equals() method, which compares this array object with the passed arrayobject, does not compare values of the array since it is inherited from the Object class. Thus we get another false. On the other hand, the Arrays class implements various equals() methods to compare two array objects of different types, hence we get true from the last invocation.

Multiple choice
  1. In sample8.sample8a()In sample8.sample8b()

  2. In sample8.sample8a()In childsample8.sample8b()

  3. In childsample8.sample8a()In sample8.sample8b()

  4. In childsample8.sample8a()In childsample8.sample8b()

  5. None of the above

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

Reference variable is of type sample8(super class) and object created is of childsample8() and as it is static, so it first call sample8a() method of super class statically and then it calls sample8b() method of derived class dynamically.

Multiple choice
  1. sample10.new sample10a().text

  2. new sample10.sample10a().text

  3. sample10.sample10a.text

  4. new sample10().sample10a.text

  5. none of the above

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

The correct way to access fields of the static inner class is to use the inner class instance along with the outerclass, so new sample10.sample10a().text will do the job.

Multiple choice
  1. 10

  2. 25

  3. Garbage value

  4. Error in the program

  5. None of these

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

This is the correct option because the scope of static variable is throughout the program, hence the assignment at line 4 changes the value of static variable to 25. So this is the correct answer.

Multiple choice
  1. 10, 20

  2. 20, 10

  3. 20, 20

  4. 10, 10

  5. Error in the program

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

Here we are calling swap() by passing address of the parameters. This is called call by reference. Line 4 : void swap(int*,int*); <= this is the prototype of function and parameters are type of int* (Integer pointer), it stores the address of integer variable. Line 6 : swap(&a,&b); <= Calling swap function by passing address of  a and b using '&' operator. a | 10 |    b | 20 |  Line 9:  Now memory address of a and b are copied to x and y, so x and y too start pointing same memory as a and ba | 10 | <--xb | 20 | <--y Now values at memory location where x and y are pointing are swapped( Line 10, 11 and 12)[*x => value at memory location where x is pointing.]a | 20 | <--xb | 10 | <--y Now, you can see a and b memory location is same but values are changed. So this is the correct answer.

Multiple choice
  1. 20.99000

  2. 20.00000

  3. 20

  4. 20.9

  5. Error in the program

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

There is an error in the program, so it will not show any output in the main function. Definition of func() is not known to compiler during compilation, so compiler assumed the return type and parameter type to int but in definition. When it sees the parameter type is float, it throws conflicting types error. So this is the correct choice.

Multiple choice
  1. 10

  2. 20

  3. 0

  4. Garbage value

  5. Compilation error

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

There is an error in the program, it will not show any output as when we write i=20 in the global scope, it is considered as a declaration and not just an assignment and the compiler assumes it as int i=20. Hence the compiler reports an error that there is a non-static declaration of 'i' after the static declaration of i, which is not allowed. So this option is correct.

Multiple choice
  1. Prints 1 to n

  2. Prints 1 to n-1

  3. Prints n

  4. Infinite loop

  5. Compilation error

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

error: address of register variable ‘n’ requested The program will not print any output because there is an error in the program. We cannot refer to the address of a register variable because it is not stored in the memory but on the registers inside the CPU. Only variable stores in the memory have an address.S o there will be an error in the program. Hence this option is correct.

Multiple choice
  1. Infinite loop

  2. Hello World is printed 65535 times

  3. Error: Calling main() function is not allowed

  4. Error: Stack overflow

  5. None of these

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

The program will run for some time, and after that it will give an error. The reason is :-A stack(call stack) is used to store information about the active subroutines of a computer program. So whenever control transfer from one function(subroutine) to another function, return address and other parameter are stored on stack.In above program main is calling itself repeatedly, it creates an infinite loop. Each call pushes return address and other parameters to call stack and it continues till stack is full. When stack is full it terminates with error : Segmentation fault (core dumped).So this is the correct answer.

Multiple choice
  1. 10, 20

  2. 10, 10

  3. 20, 10

  4. 20, 20

  5. Error in the program

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

In above program, function is called by value. In call by value parameter's copies are made. Initially at Line 6 from where swap function is called,  a = 10, b=20.    a --> | 10 |   b-->| 20 |           Now, control goes to Line 9 and values of a,b are copied to x,y. Now, x=10, y=20 and a = 10, b= 20  a --> | 10 |   b-->| 20 |  x --> | 10 |   y-->| 20 |   After these values of x and y are swapped, x=20, y=10 but still values of a and b are 10 and 20.     a --> | 10 |   b-->| 20 |  x --> | 20 |   y-->| 10 |   So whatever changes we have done in swap function is on x and y, which is a separate copy of a and b.  So this is the correct answer. 

Multiple choice
  1. Compiles with no warning and error messages

  2. Compiles with warning: conflicting types for dispalyOut

  3. Does not compile, gives error : dispalyOut not declared

  4. Compiles but throws error while linking

  5. Hi I am Robot

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

This is the correct option  because in this program we are calling the function displayout(), but we haven’t given its return type. So in the compile time, the compiler will throw an error that “Displayout was not declared in this scope”.

Multiple choice
  1. Hello from main, inside, and deepinside function

  2. Hello from main, inside

  3. Hello from main, and deepinside function, inside

  4. Error in the program

  5. None of the above

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

There will be a compile time error in the program. Definition of a function is not allowed inside body of any other function in Standard C.If you are using gcc compiler, then program compiles.So this is the correct answer.  

Multiple choice
  1. The result comes out to be 0111.

  2. The result comes out to be 1111.

  3. The result comes out to be 1000.

  4. The result comes out to be 0110.

  5. Error in the program

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

Binary of 7 is  0111. Binary of 15 is 1111. So ORing them result comes out to be 1111.