#include <iostream>
int M(int i)
{
printf("%d\n",i++);
}
int main ()
{
int i=10;
printf("%d\n",M(i));
/*
I think calling M here should print 10 and a garbage return value from the function call, as it is not returing anything.
but the output is 10 and 3 ? Can you explain this ?
*/
return 0;
}
@MiiNiPaa: I tried changing the value of i to 100 and 1000, it gives out garbage value as 4 and 5 respectively? looks like garbage value is of some significance here? I guess it's returing number of digits+1 in the number I'm inputting. O.o
@mutexe: I'm using Dev-C++ 5.7.0, it complies fine here.
You see, on PC stack is usually used to pass and return parameters and store local variables. Often when you do something like your code, you sometimes encounter leftovers from previous operation or data written later.
In your case you are probably reading printf() return value, which is amount of characters written (digits + newline). WIth optimisations turned on I get 0. Coliru crashes. http://coliru.stacked-crooked.com/a/f309890ea8668f65
So if you had an idea that this behavior is predictable, forget it.
SAdly there are little of them. And it does terrible job of determine if there is need to did that diagnostic and some diagnostics are to high in level in my opinion.
Well, nothing which cannot be fixed by fine-tuning compiler settings which you should do anyway.