5,065 views
1 votes
1 votes
how it is compiler error

int main()
{
extern int i;
printf("%d ", i);
{
int i = 10;
printf("%d ", i);
}
}
(a) 0 10 (b) Compiler Error
(c) 0 0 (d) 10 10

ans  b

3 Answers

1 votes
1 votes

int main()
{
extern int i;
printf("%d ", i);
{       // what is this thats y compiler error.
int i = 10;
printf("%d ", i);
}
}

1 votes
1 votes

http://www.geeksforgeeks.org/understanding-extern-keyword-in-c/

first understand the extern keyword

int main()
{
extern int i;// here compiler has expecting that 'i' is already defined in some file but is has not defined thats why we are getting compiler Error
printf("%d ", i);
{
int i = 10;
printf("%d ", i);
}
}

answer is option B

0 votes
0 votes
option B is correct as extern is declared but ther is no declaration of variable i.

Related questions

0 votes
0 votes
1 answer
1
2 votes
2 votes
2 answers
4
atulcse asked Jan 15, 2022
662 views
Consider the following programint find (int n) { int a = 1; for (i = 1; i < = n; i ++) for (j = 1; j < = i; j++) for (k = 1; k <= j, k++) a = a + 1; ...