Rotate image (square matrix) by 90 deg
Tue, 06 May 2025
int fun(int n)
{
static int i = 1;
if (n >= 5)
return n;
n += i;
i++;
return fun(n);
}
Your options are
A) 5 B) 6 C)7 D) 8
This question was asked in the GATE (Computer Science) Exam.
Note that i is static variable, so it will be initialized only once. And it is only incremented by 1 per call (unlike n)
| Function Call | i | n | Incremented i |
| fun(1) | 1 | 2 | 2 |
| fun(2) | 2 | 4 | 3 |
| fun(4) | 3 | 7 | - |
Hence the final value returned will be 7.
Tue, 06 May 2025
Tue, 06 May 2025
Tue, 06 May 2025
Leave a comment