Saturday, 28 September 2013

Changing the C code for desired Output

Changing the C code for desired Output

I have came across this interview question. I know it's tricky but can't
think of any approach.
Change the program so that the output of printf is always 20. Only foo()
can be changed. main() function can not be changed.
void foo()
{
// Add Here
}
int main()
{
int i = 20;
foo();
i = 100;
printf("%d", i);
//Some other computation. Doesn't have any printf statements.
return 0;
}

No comments:

Post a Comment