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 2 of 3.
Naman said:
1 decade ago
@Krishna.
Global variable is declared at the beginning of the program.
Local var. is declared within a module.
Global variable is declared at the beginning of the program.
Local var. is declared within a module.
Nidhi said:
1 decade ago
Can we use {} in between program when it is not a function or loop ?
I think not.
I think not.
Suryakanta said:
7 years ago
C programming does not support the blocks so it will not return the error.
Keya said:
9 years ago
How can we say it is an global or local variable? Please explain me.
Sameer said:
1 decade ago
Can we use {} in between our program if its not use for function?
Krishna said:
1 decade ago
What is the different b/w local variable and global variable?
Siddharth Rai said:
1 decade ago
How can we use int x=40; as a function. It is giving errors.
Siva Ram said:
1 decade ago
Is it same for the declaration as global and external?
Thamarai said:
1 decade ago
Can we declare "int x=40" as function?
Barun Mandal said:
8 years ago
I get the below output:
20 20
Is it correct?
20 20
Is it correct?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers