in Programming reshown by
359 views
0 votes
0 votes

What should be the ans. Isn’t the Function initialization should be outside main function? They are given inside main. If declaration would be outside main then ans should be C else i don’t think options are correct here. Anyone ?

in Programming reshown by
359 views

1 comment

If you keep on calling fun() then pattern will be like “ 2 6 3 6 4 6 5 6…...”.
1
1

3 Answers

2 votes
2 votes

When we declare a function F() inside the main, it means “ it is in local scope to main(), only main function can call F() and any function outside main() can’t access the function F() which is local to main()”.If any other function tries to access F() then it will give an error like a scope problem.

Reference: https://www.geeksforgeeks.org/difference-between-declaration-of-user-defined-function-inside-main-and-outside-of-main/

Credits: @raja11sep 

edited by

3 Comments

Thanks but i saw now its giving an output 2636. I got clarified after reading from GFG. check again. Its going to print because function declaration inside function is correct but definition is not correct. So options are correct and out will be 2636 Option C.
3
3

@ankit3009 @ramakrushna

When we declare a function F() inside the main, it means “ it is in local scope to main(), only main function can call F() and any function outside main() can’t access the function F() which is local to main()” , And it does not mean “the scope it till the end of the main() function” .If any other function try to access F() then it will give error like scope problem.

Answer will be C. No issue.

3
3

Okay thank you @raja11sep @ramakrushna :) Will edit.

3
3
0 votes
0 votes
2637 will be the answer.

variables which are static hold their values outside functions

2 Comments

Yeah But its given post increment so values will be print after assignment and & 7 will never gonna come in result because auto variable is going to get flushed after each function call. Please check, may be you refer the wrong value as static variable.
0
0
okay. thanks for the confirmation.

2636 will be there.

local variables wont sustain the value after fucntion call gets over. but static will sustain
0
0
0 votes
0 votes
answer is option C, second and third fun(); will increment i to 3 from 2 and j remain 6 in both the calls.

Related questions