Since b++
is post-increment,what happens to the increment of b
if used as return b++
as in the following program?
#include<stdio.h>
int foo(int);
int main()
{
int a=8;
printf("%d",foo(a));
}
int foo(int a)
{
static int b=a*a;
return b++;
}
Edit
#include<stdio.h>
int foo();
int main()
{
foo();
foo();
}
int foo()
{
static int b=1;
printf("%d\n",b);
return b++;
}
Result
1
2
As I saw in my edit, why is b
incremented at all?Isn't return
supposed to exit that function immediately?Why is b
incremented even after control returns to main()
?Aren't all activities in the function supposed to end after return?