Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

cant get the concept of this result

0 views
Skip to first unread message

dost

unread,
Nov 26, 2009, 5:32:35 AM11/26/09
to
Guess the result and then write in ur editor

void DisplayInterestingRsult2(int a, int b)
{

printf("\n\tA[%d],B[%d]\n",a,b);
}


int _tmain(int argc, _TCHAR* argv[])
{

int iInput = 0;
printf("\ni = 0 FUN(i++,++i,i++,i)\n");
DisplayInterestingRsult(iInput++,++iInput,iInput++,iInput);
}


My result is

A[2]B[3]C[0]D[3]

i could not find why is it so.

please explain.

using of printf should be ignored you can use cout.

dost

unread,
Nov 26, 2009, 5:50:53 AM11/26/09
to

Fred Zwarts

unread,
Nov 26, 2009, 5:54:49 AM11/26/09
to
dost <kapilkau...@gmail.com> typed
(in 9b86e9f7-9a37-415c...@b25g2000prb.googlegroups.com)

I wonder whether you tried to compile and link this code.
There are a lot of problems in it.
The function DisplayInterestingRsult is not defined.
Maybe you meant DisplayInterestingRsult2, but that has a different number of parameters.
There is no function main, so it will not link to a main program. So, it will not run.
Assuming you fixed the above problems, I wonder why your

printf("\ni = 0 FUN(i++,++i,i++,i)\n");

does not not show up in your result, but anything is possible, because the main problem is
undefined behaviour, because the order of evaluation of the parameter of DisplayInterestingRsult
is not defined.

dost

unread,
Nov 26, 2009, 6:14:46 AM11/26/09
to
On Nov 26, 3:54 pm, "Fred Zwarts" <F.Zwa...@KVI.nl> wrote:
> dost <kapilkaushik....@gmail.com> typed
> (in 9b86e9f7-9a37-415c-bc96-49efce1a8...@b25g2000prb.googlegroups.com)

i am sorry for my mistake.
i just copied different function.

void DisplayInterestingRsult(int a, int b, int c, int d)
{

printf("\n\tA[%d],B[%d],C[%d],D[%d]\n",a,b,c,d);
}

int _tmain(int argc, _TCHAR* argv[])
{

int iInput = 0;
printf("\ni = 0 FUN(i++,++i,i++,i)\n");
DisplayInterestingRsult(iInput++,++iInput,iInput++,iInput);

}

sorry everybody.

red floyd

unread,
Nov 26, 2009, 1:33:33 PM11/26/09
to

The result is undefined. The call to DisplayInterestingResult results
in undefined behavior -- the value of iInput is modified multiple times
without an intervening sequence point.

Therefore *ANY* answer you get can be considered "correct".

Daniel Pitts

unread,
Nov 27, 2009, 10:57:07 PM11/27/09
to
Fred Zwarts wrote:
>
> I wonder whether you tried to compile and link this code.
> There are a lot of problems in it.
> The function DisplayInterestingRsult is not defined.
> Maybe you meant DisplayInterestingRsult2, but that has a different number of parameters.
> There is no function main, so it will not link to a main program. So, it will not run.
> Assuming you fixed the above problems, I wonder why your
> printf("\ni = 0 FUN(i++,++i,i++,i)\n");
> does not not show up in your result, but anything is possible, because the main problem is
> undefined behaviour, because the order of evaluation of the parameter of DisplayInterestingRsult
> is not defined.
>

Also, what is _tmain, and where is the #include <cstdio>?

0 new messages