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
C
Correct answer
Explanation
Here we have set basefield flag as hex which will display100 in hex and output is 64. Hence, the given option is correct.
-
Infinite loop
-
Compilation error
-
Runtime error
-
1
D
Correct answer
Explanation
The basic thing that we need to remember in C is that zero means false. Now, the code inside for loop as condition is checked. Variable i is zero since we are using post-increment operator. Hence, loop is terminated and after that 1 is printed which is the final value of i. Therefore, this is the correct answer.
-
2
-
Garbage value
-
5
-
None of the above
C
Correct answer
Explanation
When expressions are seperated by comma operator, they are evaluated from left and the rightmost expressions only used for assignment. Hence, 5 is assigned to a and 5 is printed on the screen. This is the correct answer.
C
Correct answer
Explanation
As shown in the code, i is incremented two times. In first cout, 1 will be displayed and in second cout -since a is incremented twice by then, 3 is displayed. Hence, 1 3 is the correct output.
-
2 1 15
-
1 2 5
-
3 2 15
-
2 2 2
C
Correct answer
Explanation
Initially, a[1] is 1. The line i = ++a[1] increments a[1] to 2 and sets i to 2. Then j = a[1]++ sets j to 2 and increments a[1] to 3. Finally, m = a[i++] assigns a[2](which is 15) to m and increments i to 3, resulting in 3 2 15.
-
RamanDeep
-
Raman Deep
-
Deepn
-
None of these
-
10 10
-
10 1
-
1 10
-
None of these
B
Correct answer
Explanation
DIM1 is a macro that calculates the array size correctly (10) because the array name in that scope represents the whole array. In DIM2, the array decays into a pointer when passed as an argument, so sizeof(array) returns the size of a pointer, resulting in 1.
-
3 3 3 3
-
3 2 3 3
-
2 2 2 3
-
None of these
B
Correct answer
Explanation
In many C compilers, printf arguments are evaluated from right to left. Starting from the right, ++j makes j=3, then j is 3, then i++ returns 2 (and i becomes 3), and finally i is 3, resulting in the output 3 2 3 3.
-
0
-
Garbage value
-
100
-
None of these
C
Correct answer
Explanation
The extern keyword tells the compiler that the variable 'out' is defined elsewhere. Even though the actual definition of 'out' appears after the main function, the linker will correctly resolve the reference to the global variable and print 100.
-
1 2 3 pp 4 pp 5 pp
-
1 2 3 4 5
-
1 2 pp pp pp
-
Error
D
Correct answer
Explanation
The goto statement in C is restricted to jumping within the same function. Because the label 'here' is defined in fun() and the goto statement is in main(), the code will fail to compile.
-
Garbage value
-
4
-
Error
-
None of these
B
Correct answer
Explanation
The expression *a + 1 - *a + 3 simplifies mathematically because the terms *a and -*a cancel each other out. This leaves 1 + 3, which results in 4, regardless of the values stored in the array.
C
Correct answer
Explanation
The string 'Angel' is stored with a null terminator at index 5. Modifying the character at index 6 does not affect the null terminator at index 5, so printf stops at the end of 'Angel'.
-
1
-
10
-
Garbage value
-
None of these
A
Correct answer
Explanation
The scanf function returns the number of items successfully read and assigned. Since one integer is successfully scanned into variable i, scanf returns 1, which is then printed by the outer printf.
-
1111111111110
-
-1
-
fff0
-
None of these
C
Correct answer
Explanation
In a 16-bit system, -1 is represented as 0xFFFF in two's complement. Shifting this value left by 4 bits results in 0xFFF0, which is printed as fff0 by the %x format specifier.
A
Correct answer
Explanation
The expression sizeof(*p) gives the size of a char (1 byte), while sizeof(p) gives the size of the pointer itself. In many 16-bit environments, pointers are 2 bytes, leading to the output 1 2.