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 ? Programming in C programming-in-c ace-test-series output programming + – ramakrushna asked Dec 23, 2021 reshown Dec 23, 2021 by ramakrushna ramakrushna 687 views answer comment Share Follow See 1 comment See all 1 1 comment reply raja11sep commented Dec 23, 2021 reply Follow Share If you keep on calling fun() then pattern will be like “ 2 6 3 6 4 6 5 6…...”. 1 votes 1 votes Please log in or register to add a comment.
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 ankit3009 answered Dec 23, 2021 edited Dec 23, 2021 by ankit3009 ankit3009 comment Share Follow See all 3 Comments See all 3 3 Comments reply ramakrushna commented Dec 23, 2021 reply Follow Share 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 votes 3 votes raja11sep commented Dec 23, 2021 reply Follow Share @ankit3009 @ramakrushnaWhen 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 votes 3 votes ankit3009 commented Dec 23, 2021 reply Follow Share Okay thank you @raja11sep @ramakrushna :) Will edit. 3 votes 3 votes Please log in or register to add a comment.
0 votes 0 votes 2637 will be the answer. variables which are static hold their values outside functions Ankur007 answered Dec 25, 2021 Ankur007 comment Share Follow See all 2 Comments See all 2 2 Comments reply ramakrushna commented Dec 25, 2021 reply Follow Share 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 votes 0 votes Ankur007 commented Dec 25, 2021 reply Follow Share 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 votes 0 votes Please log in or register to add a comment.
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. Udhay Brahmi answered Feb 9, 2022 Udhay Brahmi comment Share Follow See all 0 reply Please log in or register to add a comment.