In the C programming language (after the C99 standard), a new keyword is introduced known as restrict.
- restrict keyword is mainly used in pointer declarations as a type qualifier for pointers.
- It doesn’t add any new functionality. It is only a way for the programmer to inform about an optimization that the compiler can make.
- When we use restrict with a pointer ptr, it tells the compiler that ptr is the only way to access the object pointed by it, in other words, there’s no other pointer pointing to the same object i.e. restrict keyword specifies that a particular pointer argument does not alias any other and the compiler doesn’t need to add any additional checks.
- If a programmer uses restrict keyword and violates the above condition, the result is undefined behavior.
- restrict is not supported by C++. It is a C-only keyword.
Example of restrict
* restrict c)
*a += *c;
*b += *c;
a = 50, b = 60, c = 70;
use(&a, &b, &c);
"%d %d %d"
, a, b, c);
If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!