cpointersprintf

C: Which character should be used for ptrdiff_t in printf?


Which character should be used for ptrdiff_t in printf?

Does C standard clearly explains how to print ptrdiff_t in printf? I haven't found any one.

int a = 1;
int b = 2;

int* pa = &a;
int* pb = &b;

ptrdiff_t diff = b - a;

printf("diff = %?", diff); // % what?

Solution

  • It's %td. See here or better still here.