reshown by
687 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 ?

reshown by

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
0 votes
0 votes
2637 will be the answer.

variables which are static hold their values outside functions
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

1 votes
1 votes
0 answers
1
2 votes
2 votes
2 answers
2
atulcse asked Jan 15, 2022
662 views
Consider the following programint find (int n) { int a = 1; for (i = 1; i < = n; i ++) for (j = 1; j < = i; j++) for (k = 1; k <= j, k++) a = a + 1; ...
1 votes
1 votes
0 answers
3
Ashish Roy 1 asked Mar 16, 2019
1,621 views
In the above 4 Statements which would print 123 as output ? Explain also.
2 votes
2 votes
2 answers
4
Parshu gate asked Nov 12, 2017
493 views
int i = 0 ;main( ){printf ( "\nmain's i = %d", i ) ;i++ ;val( ) ;printf ( "\nmain's i = %d", i ) ;val( ) ;}val( ){i = 100 ;printf ( "\nval's i = %d", i ) ;i++ ;}