Pergunta

#include <stdio.h>
main()
{
int a=1;
printf("%d %d %d %d %d\n",++a,a++,++a,++a,a++);
a=1;
printf("%d %d %d %d %d",a,a++,a,++a,a);
}

When I run it , it gives following output.

6 4 6 6 1
3 2 3 3 3

Please explain the code.

Foi útil?

Solução

The order of evaluation of function arguments is not defined, so the ++ operators could be applied in any order. You're looking at the results of undefined behaviour.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top