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
  1. 25686.0

  2. 25656.0

  3. 65556.0

  4. 65536.0

  5. Compilation error

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

This is the correct choice. The value of variable i after evaluating the expression (1048576>>8>>3>>4>>3) comes out to be 4 and the value of variable y after evaluating the expression comes out to be 8. Both the values are passed to the function “ret(i,y)” to evaluate ret(4,8). This function finds the 4 raised to power 8 and prints that value on the screen.After evaluating the value comes out to be 65536.0. So this answer is correct.

Multiple choice
  1. Default Case 1Case 2Case 3

  2. Case1Case 2Case 3

  3. Case 2Case 3

  4. Case 3

  5. Compiler Error

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

This is the correct choice. The expression (int i = 1024<<8<<3>>8>>3;) given in theCode Evaluates to 1024. So the value of variable i is 1024. The expression will be evaluated as: (1024*(2^8)*(2^3)) / ((2^8)/(2^3)). So, the value of the variable I is now 1024. Now, switch will find a case label having value 1024 and all the Statements of that case will be evaluated. Case 3 is having the value 1024. So, “Case 3” is printed on the screen. So, this answer is correct.

Multiple choice
  1. Case -1Case 1Case 0

  2. Case -1Case 1

  3. Case 0

  4. Case 1

  5. Compiler error.

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

This is the correct answer. The expression given in the code (int i = 1048576>>8>>3>>8>>3;) will be evaluated as :-1048576 / (2^8) / (2^3) / (2^8) / (2^3). This will result into a 0.so the value of variable i becomes 0.Now switch(i++ - 1 ) will result into switch(0 -1), because we have used post-increment variable on variable i, so the value of variable i will be 0 at this time. So the switch case becomes:-Switch(-1).But we are using string values in case labels to find out the matching case. So the compiler will raise an error that “Required int, Found String”. So this answer is correct.

Multiple choice
  1. 13

  2. 9

  3. 12

  4. 16

  5. 22

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

This is the correct answer. The hypot() method in java takes two arguments as hypot(x,y) and it evaluates the expression :-   sqrt(x^2 +y^2). So, this will find sqrt(5,8) which comes out to be 9.433, so now the round() function will convert it to the nearest integer value, which is 9. So, this is the correct choice.

Multiple choice
  1. Case -1 Case 1

  2. Case -1Case 1Case 0

  3. Case 0

  4. No output

  5. Error at Line 1

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

This is the correct answer. The expression given in the code (int i = 1048576>>8>>3>>8>>3;) will be evaluated as :-1048576 / (2^8) / (2^3) / (2^8) / (2^3).This will result into a 0.so the value of variable i becomes 0. Now, switch(i++ - 1 ) will result into switch(0 -1), because we have used post-increment variable on variable i, so the value of variable i will be 0 at this time. So the switch case becomes:-Switch(-1).Now, the case label having value -1 will be executed, so “case -1” gets printed on screen. But there is no break statement after Case 1, so Case 2 statements will also get executed and we find a break after default. So no further statements will be executed.So this answer is true. The correct output is Case -1 Case 1.

Multiple choice
  1. 65536.0 12

  2. 65536.0 16

  3. 25536.012

  4. 25536.012

  5. Compiler Error

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

This is the correct choice. The value of variable i after evaluating the expression (1048576>>8>>3>>4>>3) comes out to be 4 and the value of variable y after evaluating the expression comes out to be 8.Both the values are passed to the function “ret(i,y)” to evaluate ret(4,8). This function finds the 4 raised to power 8 and prints that value on the screen.After evaluating the value comes out to be 65536.0. After that, System.out.println(i^y), statement will Apply XOR operation on the Values of variable i and y, and will print the result 12 on screen. So, the correct output is: 65536.0 12

Multiple choice
  1. No Valuei is 0i is 1

  2. i is 0i is 1

  3. i is 1

  4. No output

  5. Compilation Error

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

This is the correct choice, we have declared the variable i, but we didn’t initialise it to any value. So, the compiler will raise an Error that “i has not been initialised”. So, this answer is correct.

Multiple choice
  1. 32768

  2. 10242048

  3. 2048

  4. No Output

  5. Error at Line 1

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

This is the correct answer. The expression given in the code (int i = 1048576>>8>>3>>8>>3;) will be evaluated as :-1048576 / (2^8) / (2^3) / (2^8) / (2^3).This will result into a 0.so the value of variable i becomes 0. Now, switch(1 + i++ - 1 ) will result into switch(1 + 0 -1), because we have used post-increment variable on variable i, so the value of variable i will be 0 at this time. So the switch case becomes:-Switch(0).Now the Case having label 0 will get executed and it will solve the given expression (1024<<8<<3>>8>>3) as (1024*(2^8)(2^3)) / ((2^8)/(2^3)). So it will print 1024.As we don’t have any break after case 1. So case 2 statements will also get executed and the expression in case 2 (1024<<2>>3<<2) will be evaluated as (1024(2^2) / (2^3) *(2^2)) to result 2048.Now we encountered break after default case.So the program terminated here. So the correct output is :-10242048. So this answer is true.

Multiple choice
  1. Good Bye 1024 2048 32768

  2. 1024 2048 32768

  3. 2048 32768

  4. 32768

  5. Compilation error

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

This is the correct choice, the value of variable i after evaluating the expression (1048576>>8>>3>>8>>3) + + - + (1024<<8<<3>>8>>3) comes out to be -1024.The expression is evaluated as following :-(1024*(2^8)(2^3)) / ((2^8)/(2^3)) - (1024(2^8)*(2^3)) / ((2^8)/(2^3)) = -1024. So, the switch statement becomes switch(-1024), bu there is no case label having label -1024, so the default case will be executed until a break keyword is found.So the output is: Good Bye 1024 2048 32768.So this answer is true.

Multiple choice
  1. Default CaseCase 1Case 2Case 3

  2. Case 1Case 2Case 3

  3. Case 2Case 3

  4. Case 3

  5. Compilation Error

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

This is the correct choice. The hypot() method in java takes two arguments as hypot(x,y) and it evaluates the expression :- sqrt(x^2 + y^2).So this will find sqrt(5,8) which comes out to be 167.7, so now the round() function will convert it to the nearest integer value, which is 168.We have converted the “long” value 168 into integer and passed it to switch case.Now swtich() case becomes switch(168), now the case label having value 168 will be executed.So the case 2 gets executed and printed “Case 2”, but there is no break keyword after case 2, so case 3 also gets executed. So, the correct output becomes:-Case 2Case 3.

Multiple choice
  1. HelloHow r u?Bye Bye ByeGood Bye

  2. How r u? Bye Bye Bye Good Bye

  3. Bye Bye ByeGood Bye

  4. Bye ByeGood Bye

  5. Good Bye

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

This is the correct choice, the value of variable i after evaluating the expression (1048576>>8>>3>>8>>3) + + - + (1024<<8<<3>>8>>3) comes out to be -1024.The expression is evaluated as following :-(1024*(2^8)(2^3)) / ((2^8)/(2^3)) - (1024(2^8)*(2^3)) / ((2^8)/(2^3)) = -1024.So the switch statement becomes(i++), as we have used post-increment on Variable i, so the value of variable i is still -1024. So the switch statement becomes switch(-1024), but there is no case label having label -1024, so the default case will be executed until a break keyword is found. So the output is :-Good Bye

Multiple choice
  1. Case 1Case 2Case 3

  2. Case 2 Case 3

  3. Case 3

  4. No output

  5. Compiler Error

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

This is the correct, no output will be printed on the screen. The expression (int i = 1024<<8<<3>>8>>3;) given in theCode Evaluates to 1024. So the value of variable i is 1024. The expression will be evaluated as :-(1024*(2^8)*(2^3)) / ((2^8)/(2^3)). So the value of the variable I is now 1024.Now switch will find a case having value 1024, but there is no case label having value 1024.So the Default case will be executed, but there is no statement in the Default case. So no output will be printed on the screen. So this answer is correct.

Multiple choice
  1. Valuei is 0i is 1i is 2

  2. i is 0i is 1i is 2

  3. i is 1i is 2

  4. i is 2

  5. Compilation Error

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

This is the correct choice, there is an error in the code. We have declared variable i of integer type, and we are passing i into the if() statement.If() requires a Boolean type variable and we are passing an integer value to it. So the compiler will raise an error. So this answer is correct.

Multiple choice
  1. a

  2. v

  3. Compiler Error : canoot pass a function as parameter

  4. Compiler Error : parameters not sufficient

  5. Compiler Error : parameters not sufficient

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

This is the correct answer. S.length() wil return 15 because there are 15 characters in the String. So the code looks like this :-s.charAt(15);the index count starts at 0. In this way the last character a is at index number 14. So if we try to access a character in a string which is out of bound then a runtime exception “StringOutOfBound” will be thrown. So we can pass only till s.charAt(s.length()-1). So this is correct answer.

Multiple choice
  1. ome

    • 1
  2. com

  3. Run time error

  4. Compile time error

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

This is the correct answer. Substring method takes two parameters (beginIndex,EndIndex).Substring( int Begin , int End). It return the string from begin to end – 1. But if the begin index is greater than the endindex then a runtime error will occur. So here substring(4,3) will give runtime error. So this is the correct answer.