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

  2. 1

  3. 101

  4. 111

  5. 110

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

This is the correct choice.

Multiple choice
  1. o

  2. c

  3. Empty string

  4. Compile time error

  5. Run time error

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

This is the correct answer. Substring method takes two parameters (BeginIndex, EndIndex).Substring(int Begin, int End). It returns the string from the beginning to end – 1. But if the BeginIndex is equal to the EndIndex, then an empty String with length 0 will be returned. So, here substring(4, 4) will return an empty string of length 0.  

Multiple choice
  1. a

  2. v

  3. Compiler Error : cannot pass a function as parameter

  4. Compiler Error : parameters not sufficient

  5. Run time error

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

This is the correct answer. s.length() will 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 is 'a' at index number 14. So, if we try to access a character in a string which is out of bound, then a runtime exception “StringIndexOutOfBound” will be thrown. So, we can pass only till s.charAt(s.length()-1).

Multiple choice
  1. -2147483648 and 1

  2. 0x80000000 and 0x00000001

  3. -2147483648 and -1

  4. 1 and -2147483648

  5. None of these

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

Option (1) is correct. The >>> operator moves all bits to the right, zero filling the left bits. The bit transformation looks like this: Before: 1000 0000 0000 0000 0000 0000 0000 0000 After: 0000 0000 0000 0000 0000 0000 0000 0001 Converting this into decimal, the result will be 2147483648 and 1 So, this is the correct choice.

Multiple choice
  1. Moves the put pointer by 5 bytes from the beginning of a data file

  2. Moves the get pointer by 5 bytes from the beginning of a data file

  3. Displays the contents of a data file

  4. Modifies data of a data file

  5. Deletes the contents of a data file

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

This is the correct option as seekg() function is used to move the get pointer from the beginning of a data file.

Multiple choice
  1. ome

    • 1
  2. com

  3. Runtime 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 returns the string from begin to end -1. But if the begin index is greater than the end index then a runtime error will occur. So here substring(4,3) will give a runtime error.

Multiple choice
  1. True

  2. False

    • 1
  3. Compile time error

  4. Runtime 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 does not contain any method named match(). The correct method is matches(). So the above statement should be s.matches(s1). So this is the correct answer. The program will not run. So run time error cannot occur because a compiler error is there. So this is wrong.

Multiple choice
  1. Welcome ava

  2. Welcome va

  3. Welcomeava

  4. Compiler error : delete cannot be used with StringBuffer

  5. Runtime error

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

This is the correct answer. delete(int start , int end) method deletes the characters from the start index until  the end -1 index. So, the welcome to java will delete the characters from 8 to 11 characters. Therefore, the resulting string remains “ Welcome ava”. The index starts from 0.

Multiple choice
  1. o

  2. c

  3. Empty string

  4. Compile time error

  5. Runtime error

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

This is the correct answer. Substring method takes two parameters (beginIndex,EndIndex).Substring( int Begin , int End). It returns the string from begin to end – 1. But if the begin index is equal to the end index then an empty String with length 0 will be returned. So here substring(4,4) will return an empty string of length 0. So this is the correct answer.

Multiple choice
  1. s.length() = 14s.charAt(9) = T

  2. s.length() = 15s.charAt(9) = o

  3. s.length() = 15s.charAt(9) = T

  4. s.length() = 14s.charAt(9) = o

  5. Compiler error

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

This is the correct answer. Length() function returns the number of characters in the string. The number of characters in the given string is 15. So length() will return 15.charAt() function return the character at the given index in the parameter. Remember that the index count starts at 0. So charAt(0) is W. Counting in this way we reach charAt(9) is o. So this is the correct answer.

Multiple choice
  1. a

  2. v

  3. Compiler Error : cannot pass a function as a parameter

  4. Compiler Error : parameters are not sufficient

  5. Runtime error

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 bounds then a runtime exception “StringOutOfBound” will be thrown. So we can pass only until s.charAt(s.length()-1).  So this is a correct answer.