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

Multiple choice
  1. true

  2. false

    • 1
  3. Compile time error

  4. Run time error

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

This is the correct answer. The compiler will throw an error that method match() was not declared. Because String class do not contains any method named match(). The correct method is matches(). So the above statement should be s.matches(s1). So this is the correct answer.