C restrict Qualifier

Advanced
6 min read
Updated: Nov 2026
1 example

What Is restrict Qualifier?

restrict (C99) is a promise that, during the lifetime of the pointer, the object it points to is accessed only through that pointer (or pointers derived from it). It lets the compiler optimize more aggressively, for example vectorize loops. If the promise is false, behavior is undefined. memcpy uses it; memmove does not.

Remember
void add_arrays(int n, int *restrict out,
                const int *restrict a, const int *restrict b);

Cheat Sheet

Keep these facts handy while you work with restrict Qualifier in C.

TopicDetail
MeaningNo aliasing for that object
StandardC99 and later
Examplesmemcpy, strcpy parameters
ViolationUndefined behavior

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Error Handling.

Example 1 — Add two arrays element by element

The three arrays are distinct, so restrict is valid.

C
#include <stdio.h>

static void add_arrays(int n, int *restrict out,
                       const int *restrict a, const int *restrict b) {
    for (int i = 0; i < n; i++) out[i] = a[i] + b[i];
}

int main(void) {
    int a[] = {1, 2, 3};
    int b[] = {4, 5, 6};
    int out[3];

    add_arrays(3, out, a, b);
    printf("%d %d %d\n", out[0], out[1], out[2]);
    return 0;
}

How It Works

  1. restrict says out, a, and b never overlap.
  2. The compiler can reorder or vectorize the loop.
  3. Calling add_arrays(3, a, a, b) would break the promise.

Edge Cases & Pitfalls

Check these before relying on restrict Qualifier in real programs.

alias

Passing overlapping data

Passing overlapping buffers to restrict parameters is undefined. Use memmove-style code when overlap is possible.

gain

Expecting a speedup

Gains depend on the compiler and code. Measure before you rely on it.

Key Takeaways

  • Promise: no aliasing.
  • Optimization hint.
  • Break it and behavior is undefined.

One line: restrict (C99) is a promise that, during the lifetime of the pointer, the object it points to is accessed only through that pointer (or pointers derived from it).

Frequently Asked Questions

It tells the compiler that a pointer is the only way to access that object in its scope, enabling stronger optimizations.
memcpy requires non-overlapping buffers, so its parameters are restrict. memmove handles overlap, so it cannot promise that.
Continue with "C Error Handling" next. Report and handle failures with return codes, errno, and cleanup paths. The C Advanced Concepts hub lists every topic in order.

Next: Error Handling

Report and handle failures with return codes, errno, and cleanup paths.

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful