Question : What will be the output of the following program?
#include<stdio.h>
int x=15;
void main()
{
int x=5;
printf("\n %d",x);
}
Answer : 5.
Reason : Local variable has higher priority over Global Variable
Question : What will be the output of the following program?
#include<stdio.h>
int x=15;
void main()
{
int x=5;
{
int x=1;
printf("\n %d",x);
}
}
#include<stdio.h>
int x=15;
void main()
{
int x=5;
printf("\n %d",x);
}
Answer : 5.
Reason : Local variable has higher priority over Global Variable
Question : What will be the output of the following program?
#include<stdio.h>
int x=15;
void main()
{
int x=5;
{
int x=1;
printf("\n %d",x);
}
}
Answer : 1
Reason : The variable that is more local has higher priority among all the local variables.
No comments:
Post a Comment