geeksquiz.com で次のコードに出くわしましたが、前置演算子、後置演算子、逆参照演算子を含む式が C でどのように評価されるか理解できませんでした。
#include <stdio.h>
#include <malloc.h>
int main(void)
{
int i;
int *ptr = (int *) malloc(5 * sizeof(int));
for (i=0; i<5; i++)
*(ptr + i) = i;
printf("%d ", *ptr++);
printf("%d ", (*ptr)++);
printf("%d ", *ptr);
printf("%d ", *++ptr);
printf("%d ", ++*ptr);
free(ptr);
return 0;
}
出力は次のようになります。
0 1 2 2 3
これが上記のコードの出力である理由を誰か説明してもらえますか?