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 technology
  1. Y

  2. N

  3. Will cause run time error

  4. Returns Empty

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

The Num() function converts an empty string to 0, which evaluates as truthy in the conditional check. In DataStage BASIC, the expression If Num(Arg1) Then 'Y' Else 'N' returns 'Y' because Num('') = 0, and 0 is treated as a valid numeric value that passes the conditional test.

Multiple choice technology programming languages
  1. The class does not compile because the top level class cannot be protected.

  2. The program prints "abc"

  3. The program prints "abcabc"

  4. The program does not compile because statement "test = test + test" is illegal.

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

In Java, a top-level class cannot have protected access. Only public or default (package-private) access are allowed for top-level classes. The protected modifier is only valid for class members (methods, fields, nested classes).

Multiple choice technology programming languages
  1. 1

  2. 2

  3. 3

  4. 4

  5. 5

  6. No errors

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

\l is not a valid Java escape sequence. Valid escapes are \b (backspace), \t (tab), \n (newline), \f (form feed), \r (carriage return), \' (single quote), \' + " (double quote), and \ (backslash). Attempting to use \l causes a compile-time error.

Multiple choice technology programming languages
  1. Prints: 1111111,177,127,7f

  2. Prints: 11111111,377,256,ff

  3. Compile-time error

  4. Run-time error

  5. None of the above

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

Byte.MAX_VALUE is 127. In binary: 1111111 (7 bits). In octal: 177. In decimal: 127. In hexadecimal: 7f. The toBinaryString, toOctalString, toString, and toHexString methods produce these representations separated by commas.

Multiple choice technology programming languages
  1. Prints: f,ff,7f

  2. Prints: f,ff,ff

  3. Prints: 7f,ffff,7fff

  4. Prints: ff,ffff,ffff

  5. Prints: 7fff,ffffff,7fffff

  6. Prints: ffff,ffffff,ffffff

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

Byte.MAX_VALUE = 127 = 0x7f. Character.MAX_VALUE = 65535 = 0xffff. Short.MAX_VALUE = 32767 = 0x7fff. Long.toHexString converts each to hex string representation without leading zeros.

Multiple choice technology programming languages
  1. 1

  2. 2

  3. 3

  4. 4

  5. 5

  6. 6

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

Java identifiers cannot start with # or %. Valid identifier characters are letters, digits, _, and $, but only letters, _, and $ can start an identifier. Lines 4 (#i4) and 6 (%i6) violate these rules.

Multiple choice technology programming languages
  1. With assertions enabled it prints 210210-1 followed by an AssertionError message.

  2. With assertions enabled it prints 210210 followed by an AssertionError message.

  3. With assertions enabled it prints only 210210

  4. With assertions enabled it prints nothing.

  5. With assertions disabled it prints 210210-1

  6. With assertions disabled it prints only 210210

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

When i is -1, j = -1 % 3 results in -1. In the switch, -1 goes to default. With assertions enabled, assert j == 2 fails because -1 != 2, throwing an AssertionError after printing "210210". With assertions disabled, it prints "-1".

Multiple choice technology programming languages
  1. With assertions enabled it prints ABC followed by an AssertionError message.

  2. With assertions disabled it prints ABC followed by an AssertionError message.

  3. Assertions should not be used within the default case of a switch statement.

  4. In this code example a throw statement must be used in place of the assert statement.

  5. Compile-time error

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

The code contains a compile-time error because the switch statement inside m1 does not guarantee a return value for all paths if assertions are disabled. The compiler requires a return statement or a thrown exception after the switch block.

Multiple choice technology programming languages
  1. text always precedes the

  2. text always precedes the end of the end

  3. text always precedes the end of the

  4. None of the above

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

In Perl, the * quantifier is greedy by default. The pattern start(.*)end matches from the first "start" to the last "end" in the string. Thus, $1 captures everything between "start" and the final "end", which is "text always precedes the end of the".

Multiple choice technology programming languages
  1. p is a pointer to a function that accepts an argument which is a pointer to a character and returns an integer quantity

  2. p is a function that accepts an argument which is a pointer to a character array and returns an integer quantity

  3. p is a function that accepts an argument which is a pointer to a character and returns a pointer to a 10 element integer array

  4. None of the above

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

In the declaration int p(char *a[]), p is a function that accepts an argument a, which is an array of pointers to characters (or a pointer to a character array), and returns an integer value.

Multiple choice technology programming languages
  1. null

  2. ""

  3. NULL

  4. 0

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

Java automatically initializes instance variables (fields) to default values. For reference types like String, the default value is null, not an empty string or any other value. This behavior differs from local variables, which must be explicitly initialized before use.

Multiple choice technology programming languages
  1. Compile error

  2. ave=43.33

  3. link error

  4. ave= 43.00

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

The sum is 100+10+20 = 130. Integer division 130/3 yields 43 (truncates toward zero). This integer is stored in float variable as 43.0, then printf with %.2f format shows 'ave= 43.00'. Option B is wrong because it shows 43.33, which would require floating-point division (130.0/3).