On this page
  1. ptrdiff_t
  2. Include
  3. Signature & Overview
  4. Notes & Pitfalls
  5. Example

ptrdiff_t

Prev: size_t | Up: stddef.h | Next: NULL
Rel: stddef.h, stdint, stdbool & limits Guide
Ref: cppreference — ptrdiff_t
Tags: #public #prog #c #stdlib #stddef #tier/standard


Include

#include <stddef.h>

Signature & Overview

typedef /* signed */ ptrdiff_t;

Signed integer type produced by subtracting two pointers into the same array (p2 - p1).

Notes & Pitfalls

Example

#include <assert.h>
#include <stddef.h>

int main(void) {
    int arr[5] = {0};
    ptrdiff_t dist = &arr[4] - &arr[1];
    assert(dist == 3);
}

Linked from

Related notes