Nov 13, 2010

6. Predict the output

main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}


Answer:
5 4 3 2 1
Explanation:
When static storage class is given, it is initialized once. The change in the value of a static variable is retained even between the function calls. Main is also treated like any other ordinary function, which can be called recursively.

5. Find the missing no?

Find the next term in the following series:
3, 5, 5, 19, 7, 41, 9, ?


Answer: 
71
Explanation:
The actual series is in this form
3, 3*2-1, 5, 5*4-1, 7, 7*6-1, 9, so the next term must be 9*8-1=71