C Programming - Declarations and Initializations - Discussion
Discussion Forum : Declarations and Initializations - Find Output of Program (Q.No. 12)
12.
What will be the output of the program?
#include<stdio.h>
int main()
{
int X=40;
{
int X=20;
printf("%d ", X);
}
printf("%d\n", X);
return 0;
}
Answer: Option
Explanation:
In case of a conflict between a local variable and global variable, the local variable gets priority.
Discussion:
22 comments Page 3 of 3.
Thamarai said:
1 decade ago
Can we declare "int x=40" as function?
Sebastinrichardj said:
1 decade ago
OUTPUT: 20,40
x= 40, is a global variable , x=20 is a local variable in this program,
here,In case of a conflict between a local variable and global variable, the local variable gets priority.
so, first 20 id printed ,then 40 is printed,
x= 40, is a global variable , x=20 is a local variable in this program,
here,In case of a conflict between a local variable and global variable, the local variable gets priority.
so, first 20 id printed ,then 40 is printed,
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers