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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- C | Variable Declaration and Scope | Question 1
- C | Variable Declaration and Scope | Question 2
- C | Variable Declaration and Scope | Question 3
- C | Variable Declaration and Scope | Question 4
- C | Variable Declaration and Scope | Question 5
- C | Variable Declaration and Scope | Question 7
- C | Variable Declaration and Scope | Question 8
- 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
- What is the difference between single quoted and double quoted declaration of char array?
- What happens when a function is called before its declaration in C?
- Scope rules in C
- Scope Resolution Operator Versus this pointer in C++?
- Variable Length Arrays in C and C++
- Different ways to declare variable as constant in C and C++
- How to Count Variable Numbers of Arguments in C?
- Variable length arguments for Macros
- Redeclaration of global variable in C
- Set a variable without using Arithmetic, Relational or Conditional Operator
- How to print a variable name in C?

