ProgrammingHardWipro · Cognizant pattern
What is printed?
What is printed?
void outer(void) {
int x = 1;
void inner(void) {
printf("%d", x);
}
inner();
}
int main(void) { outer(); }- A. 1
- B. 0
- C. Compile-time error: standard C does not support nested function definitions
- D. Undefined behaviour
Correct answer: C. Compile-time error: standard C does not support nested function definitions
Standard ISO C has no concept of nested function definitions at all (unlike languages such as Python or Pascal); only GCC offers this as a non-standard extension. Relying on it is a compile-time error on any strictly-conforming C compiler.
More C Programming questions
- What happens at link time? c // file1.c static int counter = 0; void increment(void) { counter++; } c // file2.c (compiled and linked with…
- What is printed? c int x = 10; void foo(void) { int x = 20; { int x = 30; printf("%d ", x); } printf("%d ", x); } int main(void) { foo()…
- What is printed? c void f(void) { int x = 5; x = x++ + ++x; printf("%d", x); } int main(void) { f(); }
- What is printed? c int f(void) { printf("f "); return 1; } int g(void) { printf("g "); return 0; } int main(void) { if (g() && f())…
- What is printed? c int f(void) { printf("f "); return 1; } int g(void) { printf("g "); return 1; } int main(void) { if (f() || g())…
- What is printed? c int globalVar = 100; void modify(void) { int globalVar = 200; globalVar += 5; printf("local:%d ", globalVar); } int…