fork(3) download
  1. #include <stdio.h>
  2.  
  3.  
  4. int main(void) {
  5. int i;
  6. int *ptr = (int *) malloc(5 * sizeof(int));
  7. int *ptr2 = ptr;
  8. int *ptr3 = ptr;
  9.  
  10. for (i=0; i<5; i++)
  11. {
  12. *(ptr + i) = i;
  13. }
  14. printf("%d ", *ptr++); //*ptr evaluated to 0, print 0, increment ptr
  15. printf("%d ", (*ptr)++); //*ptr evaluated to 1, print 1, increment ptr
  16. printf("%d ", *ptr); //*ptr evaluated to 2, print 2
  17. printf("%d ", *++ptr); //increment ptr, *ptr evaluated to 3, print 3 (but in actual it prints 2, why?)
  18. printf("%d ", ++*ptr); //*ptr evaluated to 3, increment 3, print 4 (but in actual it prints 3, why?)
  19. return 0;
  20. }
  21.  
  22.  
  23.  
Success #stdin #stdout 0s 2184KB
stdin
Standard input is empty
stdout
0 1 2 2 3