fork(28) download
  1. #include <stdio.h>
  2. #include <stddef.h>
  3.  
  4. int main(void) {
  5. int a[20] = {0};
  6. int *p = &a[3];
  7. int *q = &a[13];
  8. ptrdiff_t diff1 = q - p; // This is 10
  9. char *x = (char*)p;
  10. char *y = (char*)q;
  11. ptrdiff_t diff2 = y - x; // This is 10 times sizeof(int)
  12. printf("diff1=%d, diff2=%d\n", (int)diff1, (int)diff2);
  13. return 0;
  14. }
  15.  
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
diff1=10, diff2=40