-
The value of j at the end of the execution of the following C program int incr (int i) { static int count = 0; count = count + i; return (count); } main () {
int i j; for (i = 0; i < = 4; i + +) j = incr (i); } is
-
- 10
- 4
- 6
- 7
Correct Option: A
Count is static variable in incr(). Statement static int count = 0 will assign count to 0 only in first call. Other calls to this function will take the old values of count. Count will become 0 after the call incr(0). Count will become 1 after the call incr(1) Count will become 3 after the call incr(2) Count will become 6 after the call incr(3) Count will become 10 after the call incr(4)