Click here to Skip to main content
15,885,890 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
what is output and why for the code given below using C and standard calling convention

C
void func(int a,int b,int c)
{
   printf("%d %d %d",a,b,c);
}
main()
{     
   int temp = 5;
   func(++temp,temp++,temp);
}


The answer i got is for stdcall convention ( 7 5 7 )
on MS Visual studio 2005.

Can any please tell how it came?
Posted
Updated 22-Sep-10 0:04am
v4
Comments
CPallini 22-Sep-10 6:07am    
'C standard calling convention' is __cdecl, not __stdcall.
unikapil 22-Sep-10 6:29am    
using _stdcall keyword for windows c++.

The output might be:
"6 5 6"
Because ++temp returns temp+1 anfd temp doesn't changes, temp++ increases valueof temp by 1 and returns value before operation (i.e. 5).
 
Share this answer
 
Why don't you try yourself (there are a lot of free compilers around) instead of bothering us?
:)
 
Share this answer
 
v2
Who knows what the answer is? You can't tell as you're using undefined behaviour (at least in C90, can't really comment on C99). Don't do it - it can change at any time according to the whims of the compiler writer. Don't give them the power to make other people laugh at you.

"Just say 'NO' to evaluated arguments for diadic functions!"

Cheers,

Ash

PS: If you really want deterministic behaviour (most new folks to C expect the parameters to be 6 6 7) then write your code:

func( t + 1, t + 1, t + 2 );
t += 2;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900