Computer Knowledge

Programming Output Evaluation

1,721 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. 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. error

  2. arbitary value

  3. 612

  4. 100

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

The function signature void abc(int a[]) decays the parameter to a pointer, so a++ increments the local pointer. However, in main(), a is declared as char a[5], and passing it to abc expects an int pointer (int*), causing a type mismatch error or compilation issue in strict C compilation contexts. Additionally, type mismatch between char array and int function parameter triggers a compilation error.

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

Multiple choice technology programming languages
  1. ffff

  2. fff0

  3. 0ff0

  4. 0fff

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

In C, -1 is represented as all 1s in two's complement (0xFFFFFFFF for 32-bit or 0xFFFF for 16-bit). Left shifting by 4 positions multiplies by 16, giving 0xFFFFFFF0 (32-bit) or 0xFFF0 (16-bit). On systems where the output is 4 hex digits, this prints as fff0. Option A (ffff) would be the result without shifting, while options C and D are incorrect bit patterns.

Multiple choice technology programming languages
  1. 5 6 6 5 5

  2. 6 5 6 5 5

  3. 5 5 6 5 5

  4. 4 5 5 4 5

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

In C, the order of evaluation of printf arguments is unspecified. However, the values are computed right-to-left before printing. Starting from i=5: i++ makes 6, i-- makes 4, ++i makes 5, --i makes 4, and i is 4. But compilers may vary. On systems producing 4 5 5 4 5, this matches option D. This tests understanding of increment/decrement operators and evaluation order.

Multiple choice technology programming languages
  1. 6

  2. junk value

  3. some address

  4. error

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

The code declares 'p' as a pointer to a const int (int const *p), meaning the value pointed to cannot be modified. The line printf("%d",++(*p)) attempts to increment the value through the pointer, which violates the const qualifier. This results in a compilation error. Option D is correct.