I have a very simple question.
in this piece of code when will the value of n be decremented?
#include<stdio.h>
void func(int n)
{
//text//
}
int main()
{
int n=10;
func(n--);
return 0;
}
now when func() is called is the value of n decremented when control comes back to main() or is it decremented at that time only but n=10 is passed to func().
Please explain, also if there is a way to check the value then that will be really helpful.
When a function is called, all it’s arguments are evaluated (in an implementation-defined order) before the function can start – it’s a sequence point. So, after all the arguments are evaluated the function can finally begin.
What this means is that
n--is evaluated and yields the value10for the function. At the moment the function has begunnis already 9 but thenparameter of the function hold the value10.A simple way to check this: