cant get the concept of this result

D

dost

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.
 
D

dost

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.

i got the answer thanx
http://www2.research.att.com/~bs/bs_faq2.html#evaluation-order
 
F

Fred Zwarts

dost said:
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.

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.
 
D

dost

dost <[email protected]> typed
(in (e-mail address removed))


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.

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.

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.
 
R

red floyd

dost said:
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.

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".
 
D

Daniel Pitts

Fred said:
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>?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,244
Members
46,838
Latest member
KandiceChi

Latest Threads

Top