# C | Storage Classes and Type Qualifiers | Question 18

Output of following program

 `#include ` `int` `fun(``int` `n) ` `{ ` `    ``static` `int` `s = 0; ` `    ``s = s + n; ` `    ``return` `(s); ` `} ` ` `  `int` `main() ` `{ ` `    ``int` `i = 10, x; ` `    ``while` `(i > 0) ` `    ``{ ` `        ``x = fun(i); ` `        ``i--; ` `    ``} ` `    ``printf` `(``"%d "``, x); ` `    ``return` `0; ` `} `

(A) 0
(B) 100
(C) 110
(D) 55

Explanation: Since s is static, different values of i are added to it one by one.

So final value of s is

s = i + (i-1) + (i-2) + … 3 + 2 + 1.

The value of s is i*(i+1)/2. For i = 10, s is 55.

Quiz of this Question

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details

My Personal Notes arrow_drop_up
Article Tags :
Practice Tags :

2

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.