C | Variable Declaration and Scope | Question 6
Output?
#include <stdio.h> int main() { int x = 1, y = 2, z = 3; printf ( " x = %d, y = %d, z = %d \n" , x, y, z); { int x = 10; float y = 20; printf ( " x = %d, y = %f, z = %d \n" , x, y, z); { int z = 100; printf ( " x = %d, y = %f, z = %d \n" , x, y, z); } } return 0; } |
chevron_right
filter_none
(A)
x = 1, y = 2, z = 3 x = 10, y = 20.000000, z = 3 x = 1, y = 2, z = 100
(B) Compiler Error
(C)
x = 1, y = 2, z = 3 x = 10, y = 20.000000, z = 3 x = 10, y = 20.000000, z = 100
(D)
x = 1, y = 2, z = 3 x = 1, y = 2, z = 3 x = 1, y = 2, z = 3
Answer: (C)
Explanation: See Scope rules in C
Quiz of this Question
Recommended Posts:
- C | Variable Declaration and Scope | Question 7
- C | Variable Declaration and Scope | Question 2
- C | Variable Declaration and Scope | Question 8
- C | Variable Declaration and Scope | Question 5
- C | Variable Declaration and Scope | Question 4
- C | Variable Declaration and Scope | Question 3
- C | Variable Declaration and Scope | Question 1
- Can we access global variable if there is a local variable with same name?
- Internal static variable vs. External static variable with Examples in C
- Scope rules in C
- What happens when a function is called before its declaration in C?
- Scope Resolution Operator Versus this pointer in C++?
- What is the difference between single quoted and double quoted declaration of char array?
- How to print a variable name in C?
- Redeclaration of global variable in C