extern int y=5;main(){int x=10,y=0;x=x+5;

extern int y=5;

main()

{

int x=10,y=0;

x=x+5;

funct(x);

printf("%d%d",x,y);

}

funct(int x)

{

int i,y;

for(i=0;i<=x;i+=2)

{

y=y+i;

}

}

2Comments
TarGate @tar_gate
13 Dec 2014 05:42 pm

It will print 150. x=15, y=0 concatenated.

Externs are majorly used to declare variables in one file, but to be defined and used in some another file. For the following code it does not use the extern y in either of the functions (main and funct) as each of these functions have initialized their own y. The funct function assigns random value to y and executes the loop, but that value is not returned, so it doesnt reflect anywhere.

Bhupathi Vaibhav @kiranvaibhav
13 Dec 2014 09:14 pm

Thank You. So Y becomes auto right

Pages