C | Storage Classes and Type Qualifiers | Question 11
Consider the following C function
int f( int n) { static int i = 1; if (n >= 5) return n; n = n+i; i++; return f(n); } |
chevron_right
filter_none
The value returned by f(1) is (GATE CS 2004)
(A) 5
(B) 6
(C) 7
(D) 8
Answer: (C)
Explanation: Since i is static, first line of f() is executed only once.
Execution of f(1) i = 1 n = 2 i = 2 Call f(2) i = 2 n = 4 i = 3 Call f(4) i = 3 n = 7 i = 4 Call f(7) since n >= 5 return n(7)
Recommended Posts:
- C | Storage Classes and Type Qualifiers | Question 9
- C | Storage Classes and Type Qualifiers | Question 12
- C | Storage Classes and Type Qualifiers | Question 19
- C | Storage Classes and Type Qualifiers | Question 3
- C | Storage Classes and Type Qualifiers | Question 7
- C | Storage Classes and Type Qualifiers | Question 19
- C | Storage Classes and Type Qualifiers | Question 14
- C | Storage Classes and Type Qualifiers | Question 19
- C | Storage Classes and Type Qualifiers | Question 19
- C | Storage Classes and Type Qualifiers | Question 6
- C | Storage Classes and Type Qualifiers | Question 18
- C | Storage Classes and Type Qualifiers | Question 19
- C | Storage Classes and Type Qualifiers | Question 8
- C | Storage Classes and Type Qualifiers | Question 19
- C | Storage Classes and Type Qualifiers | Question 19