509 views
0 votes
0 votes
#include<stdio.h>
int a = 10;
int main()
{
fun();
fun();
return 0;
}
int fun()
{
static int a = 1;
printf("%d ",a);
a++;
return 0;
}

1 Answer

Best answer
5 votes
5 votes

@Lord_Krishna Indeed output is 1 2.

Because in

1) presence of local variable with the same name, function will never access the global variable

2) Static variable declaration will takes place only once. So it can retain its value in different function calls. 

selected by

Related questions

0 votes
0 votes
1 answer
2
Desert_Warrior asked May 16, 2016
591 views
#include<stdio.h #include<stdlib.h int main() { char s[] = "Opendays2012"; int i = 0; while(*(s++)) i++; printf("%d",i); return 0; }(a) Segmentation Fault (b) Compile Err...
1 votes
1 votes
1 answer
3
0 votes
0 votes
1 answer
4