- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Restrict keyword in C
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