edited by
8,940 views

3 Answers

Best answer
16 16 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 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
1 1 vote

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:
Position:
Show:

Related questions

11 11 votes
5 answers 5 answers
10.1k
10.1k views
go_editor asked Jun 21, 2016
10,089 views
The for loopfor (i=0; i<10; ++i) printf("%d", i&1);prints0101010101011111111100000000001111111111
11 11 votes
4 answers 4 answers
12.3k
12.3k views
go_editor asked Jun 21, 2016
12,343 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 ...
9 9 votes
2 answers 2 answers
10.7k
10.7k views
go_editor asked Jun 21, 2016
10,720 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
17 17 votes
8 answers 8 answers
14.5k
14.5k views
milankamilya asked Jun 14, 2016
14,546 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