1,141 views
6 votes
6 votes
extern int i;
int i=5;

i=10;
int main()
{
  printf("\ni=%d",i);
  return 0;
}

output is?

2 Answers

1 votes
1 votes
I m sure it will throw compile error because

C never allow to do assignment in global section  because when execution starts first it will provide memory to global variable which are initialize or define and then compiler will search for main function to start execution .

Here  compiler is expecting only initialization in global section not assignment.

rest of part in program looks ok i mean extern int i  is declaration and declaration can be done any number of times,   int i = 5 initialization no issue in this part . but assignment i=10 in global section  is incorrect we will get error.
0 votes
0 votes
It will throw error as Undefined symbol. No initialization which means No memory created... extern keyword doesn't require memory. It will use external memory (global variable static memeory)

Related questions

1 votes
1 votes
2 answers
1
go_editor asked Mar 26, 2020
1,463 views
After $3$ calls of the $c$ function bug ( ) below, the values of $i$ and $j$ will be :int j = 1; bug () { static int i = 0; int j = 0; i++; j++; return (i); }$i = 0, j = ...
1 votes
1 votes
8 answers
2
go_editor asked Mar 26, 2020
2,241 views
Find the output of the following $“C”$ code :Main() { int x=20, y=35; x=y++ + x++; y=++y + ++x; printf (“%d, %d\n”, x, y); }$55, 93$$53, 97$$56, 95$$57, 94$
3 votes
3 votes
2 answers
3