Question 92

Computer Awareness Data Structure Easy

Predict the output of the following C Code

int x = 0;
int f()
{
int g()
{
int x = 1;
return f();
}
int main()
{
printf('%d', g());
printf('/n');
getchar();
}

(A) 1
(B) 0
(C) Garbage value
(D) 2
✓ Correct Answer: Option B Verified Solution

📘 Step-by-Step Solution & Detailed Explanation:

The code (cleaned up) is:

int x = 0;
int f() { return x; }
int g() { int x = 1; return f(); }
int main() { printf("%d", g()); }

C uses static (lexical) scoping. Inside f(), the name x refers to the global x, which is 0. The local x = 1 inside g() is not visible to f().

So g() returns f() = 0, and the output is 0.

Answer: (B) 0

Practice Similar Data Structure Questions

Reinforce your conceptual grasp with related questions from MAH MCA CET 2024:

Q81 The clarity of an image on the screen, measure in pixels. The higher...
Solve →
Q82 A ............. contains a list of commands from which a user can make...
Solve →
Q83 The portion of the process scheduler in an operating system that...
Solve →
Q84 One of the most negative impact to computer technology is \( \) .
Solve →
Q85 Perform Two's complement addition of two negative numbers \( (11101) 2 \)...
Solve →
Full-Length Test Series

Prepare for MAH MCA CET Under Real Exam Conditions

Take timed full-length mock tests with authentic question distributions, negative marking (+12/-3 in Math), and instant All India Rank calculation.

Start Free Mock Test Series →