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
The output of the following program is
main()
{
int a, b, c;
int num[3][4]= {1,2,3,4,5,6,7,8,9,10,11,12};
for(a=0;a<3;++a)
{
c=999;
for(b=0;b <4;++b)
if (z[a][b]<c)
c=z[a][b];
printf(“ %d”,c);
}
}
-
1 5 9
-
4 8 12
-
1 4 7 10
-
1 3 6 9 12
A
Correct answer
Explanation
The code has multiple errors: it declares 'num' but uses 'z' in the comparison, and uses HTML entities (<) instead of operators. If we assume it meant to use 'num' and proper '<' operators, each iteration finds the minimum value in a row. Row 0 minimum is 1, row 1 minimum is 5, row 2 minimum is 9, so output would be '1 5 9'.
-
for(i=0;i<80;++i)
-
for(i=0;i<=60;i++)
-
for(i=1;i<60;i++)
-
for(i=0;i<60;++i)
D
Correct answer
Explanation
To read exactly 60 characters, the loop must run 60 times with index starting at 0 and going up to (but not including) 60. The condition 'i<60' achieves this - it runs for i=0,1,2,...,59, which is exactly 60 iterations. This stores characters at indices 0 through 59.
-
pigeon
-
3
-
2
-
none of the above
A
Correct answer
Explanation
The expression x-- uses the postfix decrement operator, which returns the current value (7) before decrementing x to 6. So z = 7 - 6 = 1. If it were --x, the answer would be 0.
-
Ram Krish
-
Ram Krisha
-
Ram Krishan
-
Ram Krishan Verma
A
Correct answer
Explanation
cin.getline(a,10) reads up to 9 characters plus null terminator. 'Ram Krishan Verma' is truncated to 'Ram Krish' (9 chars) then null-terminated. getline stops at the buffer limit, preserving whatever fits.
-
Base address of z
-
5
-
6
-
Unknown value
C
Correct answer
Explanation
p points to z[0]=5. *p+1 dereferences p (getting 5) then adds 1, giving 6. The precedence is: (*p) + 1, not *(p+1). The latter would give z[1]=6, but that's not what's written.
B
Correct answer
Explanation
The loop runs exactly once: a starts at 100, condition (a>=100) is true, 'hello' is printed, then --a decrements a to 99. On the next iteration, condition (99>=100) is false, so the loop exits.
-
pigeon
-
3
-
2
-
none of the above
C
Correct answer
Explanation
Enums assign integers starting from 0: parrot=0, crow=1, pigeon=2, sparrow=3. Since b is assigned pigeon (the third element), it has value 2. The output is the numeric value, not the name.
-
Winter Autumn
-
Autumn
-
Summer Autumn
-
Winter
A
Correct answer
Explanation
Tracing the nested conditions with p=10, q=20, r=30: First if (p>10)||(q<30) evaluates to (false)||(false) = false, so we skip to the final cout statement and print 'Autumn'. The inner if-else blocks are never executed.
-
Base address of z
-
5
-
6
-
None of the above
C
Correct answer
Explanation
The pointer p points to z[0](value 5). The expression *p+1 dereferences p first (getting 5), then adds 1, resulting in 6. Dereference has higher precedence than addition.
B
Correct answer
Explanation
The pointer p points to m (value 10). (*p)++ increments m to 11. Then cout<<(*p)++ prints 11 (post-increment returns the value before incrementing). Final value of m is 12, but output is 11.
-
class stars
-
class moon
-
class sun
-
none of the above
D
Correct answer
Explanation
This code has a compilation error due to diamond inheritance ambiguity. Class stars inherits from both sun and moon, each having a result() method. Calling s.result() is ambiguous - the compiler cannot determine which result() to use. This requires scope resolution (s.sun::result() or s.moon::result()) or virtual inheritance.
-
class stars
-
class moon
-
class sun
-
none of the above
D
Correct answer
Explanation
This code has a compilation error due to diamond inheritance ambiguity. Class stars inherits from both sun and moon, each having a result() method. Calling s.result() is ambiguous - the compiler cannot determine which result() to use. This requires scope resolution (s.sun::result() or s.moon::result()) or virtual inheritance.