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

  2. An exception is thrown at runtime

  3. The variable first is set to null.

  4. The variable first is set to elements[0].

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

The ternary operator checks if elements.length > 0 (true since array has 3 elements), so it returns elements[0] which is 'for'. The colon separates the true and false branches - elements[0] is assigned to first. The array initialization syntax is valid.

Multiple choice technology programming languages
  1. String value.............null

  2. Exception

  3. Compiler Error

  4. Integer value.............0

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

The code creates ambiguity because both overloaded displayVal methods can accept zero arguments. The String... varargs and int... varargs methods are both valid candidates for the call displayVal() with no parameters. Java cannot determine which method to invoke, resulting in a compile-time error.

Multiple choice technology programming languages
  1. No observations

  2. x y {A 1} {A 2} {B 2}

  3. x y {A 1} {A 2}

  4. x y {A 1} {A 2} {B .}

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

The SAS DATA step uses line-hold specifier @ to hold the current record. For 'A' records, it reads the next line/value y. For the 'B' record, it doesn't execute the inner input for y, causing y to remain missing (.) for that observation. The output contains observations for A (1), A (2), and B (.).

Multiple choice technology programming languages
  1. 10

  2. 1000

  3. error

  4. none of this

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

The ternary operator attempts to declare variables directly in its branches: (int a = 100) and (int a = 1000). In C, variable declarations are statements, not expressions, and cannot appear inside a ternary operator. The scope issue is also problematic - even if allowed, 'a' would not be visible in the printf statement. This code will not compile and produces an error.

Multiple choice technology programming languages
  1. error

  2. 25

  3. will not complie

  4. some memory address

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

In C, a void pointer (void*) can be implicitly assigned to any other pointer type without explicit casting. This is a special property of void pointers. After p1=p2 and p2=p1, both pointers still point to i, which holds value 25. The printf correctly outputs 25. The 'will not compile' distractor is incorrect because void* to other pointer assignment is valid in C.

Multiple choice technology programming languages
  1. I hate you

  2. I love your

  3. error

  4. will not compile

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

The line if(me = = you) is problematic. In C, the assignment operator is '=' not ' = '. The 'me = = you' appears to be a typo for 'me == you'. Assuming it means 'me == you': me is float (1.1) and you is double (1.1). Due to floating point representation differences, they may not compare exactly equal. Float and double have different precision. Typically 1.1 as float != 1.1 as double in binary representation. So the condition is false, and 'I hate you' prints. Also note that even if it was 'me == you', the comparison would be false due to precision differences.

Multiple choice technology programming languages
  1. GOOD

  2. BAD

  3. ERROR

  4. NONE OF THESE

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

In a switch statement, case labels must be constant expressions, not variables. The code uses 'case i:' and 'case j:' where i and j are variables (int i=1, j=2). This is invalid syntax - case labels cannot be runtime variable values. The compiler will generate an error. The switch structure also has a semicolon after the closing brace, which is unusual but not an error.

Multiple choice technology programming languages
  1. junk value

  2. 100

  3. 12

  4. none of these

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

The macro f(g,g2) is defined as g##g2 (token concatenation using ## operator). When called as f(var,12), it concatenates 'var' and '12' to produce 'var12'. The printf becomes printf('%d', var12). Since var12 is declared as int var12=100, it outputs 100. The ## operator performs token pasting during preprocessing, not string concatenation.

Multiple choice technology programming languages
  1. -1 -1 0 2 0

  2. -1 -1 0 2 1

  3. 0 0 1 3 1

  4. 0 0 1 3 0

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

The expression m=i++&&j++&&k++||l++ uses short-circuit evaluation with post-increment. Starting: i=-1, j=-1, k=0, l=2. First i++ evaluates to -1 (true), then i becomes 0. Since -1 (true) && j++, we evaluate j++: j=-1 evaluates to -1 (true), then j becomes 0. Now we have (-1 && -1) which is 1 (true) && k++. But wait, i++ and j++ both happened. Now: i=0, j=0, k=0. Continuing: true && k++ means evaluate k++: k=0 evaluates to 0 (false), then k becomes 1. Short-circuit! Since k++ was false (0), the entire AND chain becomes false without needing more evaluation. m = (false) || l++, so we evaluate l++: l=2 evaluates to 2 (true), then l becomes 3. m = false || true = 1. Final values: i=0, j=0, k=1, l=3, m=1. This matches option C.

Multiple choice technology programming languages
  1. 0

  2. 1

  3. infinite loop

  4. 0 1

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

The for loop is: for( ; i++ ; printf('%d',i)). Initial condition is empty (uses i=0). The condition is i++, which is a post-increment: First iteration: i++ evaluates 0 (current value of i), then i becomes 1. Since 0 is false, the loop condition fails immediately. The printf inside the loop never executes. After loop exit, printf('%d',i) outputs 1 (the value of i after the post-increment in the condition check).