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 programming languages
  1. Undefined

  2. 01

  3. 00

  4. 10

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

In C++, modifying a variable twice without an intervening sequence point causes undefined behavior. Here c++ both modifies c and yields its original value, but there's no sequence point between the two c evaluations in the cout statement. This violates sequencing rules, making the output undefined rather than predictably 01, 00, or 10.

Multiple choice technology programming languages
  1. Outputs 12

  2. Outputs 10

  3. Outputs the address of v

  4. Undefined

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

In main, v is initialized to 10. Its address is passed to afunction. Inside afunction, the local pointer parameter x is reassigned to point to a newly allocated memory address, leaving the original variable v in main completely unmodified. Thus, v remains 10.

Multiple choice technology operating systems
  1. checks prime number; returns one when not prime and zero when prime

  2. checks prime number; returns none when not prime and zero when prime

  3. checks prime number; returns zero when not prime and one when prime

  4. checks prime number; returns zero when not prime and none when prime

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

This script checks if $l is prime by testing divisibility from 2 upward. If $l % i == 0 (divisible), it prints and breaks with exit status 0 (success). If no divisor found, loop completes naturally, exit status is 1 (failure) from the last comparison. The 'print' statement only executes when not prime (divisor found), so output appears when not prime; no output when prime.

Multiple choice technology operating systems
  1. checks prime number; returns one when not prime and zero when prime

  2. checks prime number; returns none when not prime and zero when prime

  3. checks prime number; returns zero when not prime and one when prime

  4. checks prime number; returns zero when not prime and none when prime

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

This is a duplicate of question 136523. The script tests if $l is prime by checking divisibility. If divisible (not prime), it prints and exits with status 0. If no divisor found (prime), loop ends with exit status 1 from the last comparison. Output appears when not prime, none when prime.

Multiple choice technology operating systems
  1. #On the beach at night, stands a child with her father

  2. #On #the #at #a #with #her

  3. #beac #nigh #stan #chil #fath

  4. #beach #night, #stands #child #father

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

The script loops through each word in the input string, checking if its length exceeds 4 characters using ${#i}. Words longer than 4 characters are printed with a '#' prefix. From the input, the qualifying words are: beach (5), night, (6 including comma), stands (6), child (5), and father (6). Option D correctly shows these words prefixed with '#'.

Multiple choice technology operating systems
  1. checks prime number; returns one when not prime and zero when prime

  2. checks prime number; returns none when not prime and zero when prime

  3. checks prime number; returns zero when not prime and one when prime

  4. checks prime number; returns zero when not prime and none when prime

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

The script checks if a number $l is prime by testing divisibility from 2 to l-1. The 'break' statement exits when a divisor is found. The key is understanding that 'print $?' displays the exit status of the last command - 'break' exits with status 0 (success), so when a divisor is found (not prime), it prints 0. When no divisor is found (prime), the loop completes normally and nothing is printed (none/empty).

Multiple choice technology programming languages
  1. Compile-Time Error

  2. a=5 b=10

  3. a=10 b=5

  4. None of the above

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

The macro definition has malformed backslashes - they should only appear at line endings for continuation, not before each statement. Also, the macro call 'Swap;' lacks proper syntax. The preprocessor will fail to parse this correctly, resulting in a compilation error.

Multiple choice technology programming languages
  1. Compile-Time Error

  2. 50 50

  3. 50 0

  4. None of the above

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

A void pointer can hold the address of any data type. When we assign &val to ptr, then cast ptr back to (int*) before dereferencing, we correctly retrieve the original value 50. The program prints the value twice - once directly from val, once through the pointer.

Multiple choice technology programming languages
  1. Compile-Time Error

  2. 5 6 30

  3. 4 7 28

  4. None of the above

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

The expression --a*++b has both operators executing before multiplication: --a decrements a from 5 to 4, ++b increments b from 6 to 7, then 4*7 = 28. printf evaluates arguments left-to-right, so a and b are printed after the increments: 4 and 7.