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
C
Correct answer
Explanation
This is the correct choice.
Which of the following syntax will return the size of the array @My_array
@My_array = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
-
@My_array
-
print @My_array
-
print $My_array
-
$size = @My_array;
print $size;
-
$size1 = $#My_array;
print $size1;
D
Correct answer
Explanation
Yes, scalar variable will get the size of array @My_array
-
print scalar @My_array
-
$my_arr_size = @My_array
print $my_arr_size
-
print $#My_array
-
print 0+@My_array
-
print $#My_array + 1
C
Correct answer
Explanation
Yes, It returns the maximum index of the array, i.e. one less than the size of the array.
-
o
-
c
-
Empty string
-
Compile time error
-
Run time error
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.
-
a
-
v
-
Compiler Error : cannot pass a function as parameter
-
Compiler Error : parameters not sufficient
-
Run time error
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).
-
-2147483648 and 1
-
0x80000000 and 0x00000001
-
-2147483648 and -1
-
1 and -2147483648
-
None of these
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.
-
null value
-
integer
-
float
-
char
-
based on function
A
Correct answer
Explanation
The void returns no value during execution of the function.
-
Moves the put pointer by 5 bytes from the beginning of a data file
-
Moves the get pointer by 5 bytes from the beginning of a data file
-
Displays the contents of a data file
-
Modifies data of a data file
-
Deletes the contents of a data file
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.
-
Run time error
-
Successful execution
-
Compile time error
-
None of these
C
Correct answer
Explanation
Range of short variable is between -32,768 to 32,767. So, java compiler gives compile time error.
-
ome
-
-
com
-
Runtime error
-
Compile time error
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.
-
True
-
False
-
-
Compile time error
-
Runtime error
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.
-
Welcome ava
-
Welcome va
-
Welcomeava
-
Compiler error : delete cannot be used with StringBuffer
-
Runtime error
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.
-
o
-
c
-
Empty string
-
Compile time error
-
Runtime error
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.
-
s.length() = 14s.charAt(9) = T
-
s.length() = 15s.charAt(9) = o
-
s.length() = 15s.charAt(9) = T
-
s.length() = 14s.charAt(9) = o
-
Compiler error
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.
-
a
-
v
-
Compiler Error : cannot pass a function as a parameter
-
Compiler Error : parameters are not sufficient
-
Runtime error
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.