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
-
Num variable of Myclass is initialized to 10
-
Run Time Error
-
Compiler Error
-
StackOverflow Exception
C
Correct answer
Explanation
The code has a compiler error because variable 'c' is declared without the 'Dim' keyword. In VB.NET, all variable declarations require 'Dim', 'Public', 'Private', or similar keywords. The line 'Dim c as Myclass' is missing this keyword.
-
Num variable of Myclass is initialized to 10
-
Run Time Error
-
Compiler Error
-
StackOverflow Exception
C
Correct answer
Explanation
The constructor in MyClass is declared as Private, which means it cannot be accessed from outside the class. When Test.Main tries to create an instance with 'C=New Myclass(10)', the compiler detects this accessibility violation and fails before runtime.
-
x is greater
-
y is greater
-
compile error
-
none
A
Correct answer
Explanation
When comparing a signed integer (-2) with an unsigned integer (12), C converts the signed value to unsigned. -2 becomes a large positive number (approximately 4 billion for 32-bit int), so it is greater than 12. The output is 'x is greater'.
-
012046056
-
124656
-
103846
-
010038046
C
Correct answer
Explanation
In C, integers starting with 0 are interpreted as octal. 012 octal = 10 decimal, 046 octal = 38 decimal, 056 octal = 46 decimal. The printf outputs these decimal values.
A
Correct answer
Explanation
In C, evaluating ++x * ++x (where x starts at 5) is undefined behavior. On many compilers (like GCC), both increments execute before the multiplication, making x become 7, and the multiplication evaluates to 7 * 7 = 49. Although undefined, 7 and 49 is the classic compiler output represented by the stored correct option.
D
Correct answer
Explanation
The static variable count persists across function calls. The loop calls counter(0) through counter(5), accumulating: 0+1+2+3+4+5 = 15. The final value returned is 15.
C
Correct answer
Explanation
The struct s is initialized with a=3, b=5, c=6. The pointer pt points to s. Casting pt to (int*) and dereferencing reads the first integer member, which is a with value 3.
-
2,1
-
2,5
-
compile error
-
2,2
B
Correct answer
Explanation
*(a+1) accesses the second element (index 1) = 2. (&a+1) points past the entire array, so ptr-1 points to the last element = 5. Output is '2 5'.
C
Correct answer
Explanation
In C, the comma operator evaluates its left operand, discards the result, and returns the right operand. Thus, c = a, b; binds as (c = a), b; due to operator precedence, setting c to 3. Meanwhile, d = (a, b); evaluates the group, setting d to 5. The printed output is c = 3 and d = 5, which is matches option '3,5'.
B
Correct answer
Explanation
Shifting -1 (which is represented as all bits set, e.g., 0xffff in 16-bit) left by 4 bits yields 0xfff0. When printed as a hex value using '%x', this prints as 'fff0' (or 'fffffff0' on 32-bit systems, but 'fff0' is the intended output for a 16-bit integer context). The decimal representation -16 is wrong due to the '%x' format specifier.
-
O
-
H
-
HELLO
-
Compilation Error
D
Correct answer
Explanation
The code attempts to initialize a 4-element character array with a 6-character string literal (5 characters + null terminator). In C, array initialization with an oversized string literal is a compilation error because the initializer exceeds the declared array size. While some compilers might allow this as an extension with a warning, standard C requires compilation error. The program cannot execute as written due to this initialization error.
#include main() { int a[2][2][2] = {{10,2,3,4},{5,6,7,8}}; int p,*q; p=&a[2][2][2]; *q=**a printf("%d----%d",*p,*q); }
-
Compilation error
-
syntax error
-
10 2 3 4 5 6 7 8
-
print the address of pointer p and q
A
Correct answer
Explanation
The code contains a syntax error because the statement *q=***a is missing a terminating semicolon. This prevents compilation. Additionally, main() lacks an explicit return type, which modern C compilers reject. Distractors are incorrect because the code cannot run to output any data or addresses.
-
value @c: ffffffad
-
value @c: 0xf0ad
-
compilation error
-
syntax error
A
Correct answer
Explanation
On a little-endian system (x86/x64), the 32-bit value 0xf0ad is stored in memory as bytes 0xad 0xf0 0x00 0x00 (least significant byte first). When cast to char*, the pointer addresses the first byte (0xad). When this char value (0xad = -1 as signed char) is promoted to int for printf with %x, sign extension extends it to 0xffffffffad, which printf displays as ffffffad. This demonstrates endianness and sign extension behavior.
-
23
-
Prints some address
-
Compilation error
-
Run time error
C
Correct answer
Explanation
The code declares 'i' as extern but never defines it. An extern declaration tells the compiler that the variable exists elsewhere, but without a definition, the linker cannot resolve the symbol. The assignment 'i=23;' attempts to use an undefined external symbol, which causes a linkage error during compilation/linking. Every extern variable must have exactly one definition in some translation unit.
C
Correct answer
Explanation
The static array a[] is initialized to 0. The statement a[i]=i++ where i=0 has undefined behavior in C (modifying and reading i in same expression), but in practice: a[0] is assigned 0, then i increments to 1. The output shows a[0]=0, a[1]=0 (unchanged static value), and i=1.