edited by
6,608 views

3 Answers

Best answer
15 votes
15 votes

answer is B)

As static is implicitly initialized to 0

and inc() is called 3 times

hence output will be 1,2,3

selected by
2 votes
2 votes
Answer (B)

x is static so during initialization it's value is 0,with every call it increases by 1

first call = 0+1 =1

second call= 1+1=2

third call = 2+1 = 3

so 123 is printed
0 votes
0 votes

Important points about the static variables:- 

  • They're initialised right at the start, and their value are stored inside the Runtime Environment.
  • Once initialised, they're never initialised again.
  • If in the beginning, value is not assigned for initialisation, then it is assigned 0 by default.
    static int x;

Value assigned 0 implicitly. So, x = 0.

Combine this fact with pre-increment, we get option B

Answer:

Related questions

9 votes
9 votes
5 answers
1
go_editor asked Jun 21, 2016
6,121 views
The for loopfor (i=0; i<10; ++i) printf("%d", i&1);prints0101010101011111111100000000001111111111
10 votes
10 votes
4 answers
2
go_editor asked Jun 21, 2016
9,377 views
The output of the following program ismain() { static int x[] = {1,2,3,4,5,6,7,8} int i; for (i=2; i<6; ++i) x[x[i]]=x[i]; for (i=0; i<8; ++i) printf("%d", x[i]); }1 2 3 ...
8 votes
8 votes
2 answers
3
go_editor asked Jun 21, 2016
7,631 views
Consider the following program fragmenti=6720; j=4; while (i%j)==0 { i=i/j; j=j+1; }On termination j will have the value4896720
13 votes
13 votes
8 answers
4
milankamilya asked Jun 14, 2016
8,442 views
If n has 3, then the statement a[++n]=n++;assigns 3 to a[5]assigns 4 to a[5]assigns 4 to a[4]what is assigned is compiler dependent