What is the restrict keyword in C?

Use of restrict keyword

  • The restrict keyword is used to declare pointers as a type qualifier
  • It is the only way to inform the programmer about optimizations. It doesn’t add any new functionality.
  • If we use the keyword restrict with some pointer ptr, then ptr is the only way to access the object
  • If we use the restrict keyword wrong, it’ll be error-prone
  • The restrict keyword is not available in C++

Code

#include <stdio.h>
// In this function we are adding the value of variable z to other variables x and y
void function(int* x, int* y, int* restrict z)
{
*x += *z; // Updating value of variable x by adding the value of variables x and z
*y += *z; // Updating value of variable y by adding the value of variables y and z
}
int main(void)
{
int x = 50 , y = 100 , z = 150 ;
function(&x, &y, &z);
printf("%d %d %d", x, y, z);
}

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved