Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

1 Answer
Smita Kapse

Here we will see what is the restrict keyword in C. The restrict keyword first introduced in C99 version. Let us see what is actually this restrict keyword.

  • The restrict keyword is used for pointer declarations as a type quantifier of the pointer.

  • This keyword does not add new functionalities. Using this the programmer can inform about an optimization that compiler can make.

  • When the restrict keyword is used with a pointer p, then it tells the compiler, that ptr is only way to access the object pointed by this. So compiler will not add any additional checks.

  • If the programmer uses restrict keyword then violate the above condition, it will generate some un-defined behavior.

Example

#include <stdio.h>
void my_function(int* x, int* y, int* restrict z) {
   *x += *z;
   *y += *z;
}
main(void) {
   int x = 10, y = 20, z = 30;
   my_function(&x, &y, &z);
   printf("%d %d %d", x, y, z);
}

Output

40 50 30

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.