
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
“register” keyword in C
Register variables tell the compiler to store the variable in CPU register instead of memory. Frequently used variables are kept in registers and they have faster accessibility. We can never get the addresses of these variables. “register” keyword is used to declare the register variables.
Scope − They are local to the function.
Default value − Default initialized value is the garbage value.
Lifetime − Till the end of the execution of the block in which it is defined.
Here is an example of register variable in C language,
Example
#include <stdio.h> int main() { register char x = 'S'; register int a = 10; auto int b = 8; printf("The value of register variable b : %c\n",x); printf("The sum of auto and register variable : %d",(a+b)); return 0; }
Output
The value of register variable b : S The sum of auto and register variable : 18
Register keyword can be used with pointer also. It can have address of memory location. It will not create any error.
Here is an example of register keyword in C language
Example
#include<stdio.h> int main() { int i = 10; register int *a = &i; printf("The value of pointer : %d", *a); getchar(); return 0; }
Output
The value of pointer : 10
- Related Questions & Answers
- “extern” keyword in C
- How does the “this” keyword work in JavaScript?
- What does the “yield” keyword do in Python?
- Header files “stdio.h” and “stdlib.h” in C
- “volatile” qualifier in C
- Difference between “int main()” and “int main(void)” in C/C++?
- Deletions of “01” or “10” in binary string to make it free from “01” or “10” in C++ Program
- Python Object Comparison “is” vs “==”
- Deletions of “01” or “10” in binary string to make it free from “01” or “10" in C++?
- What is the “get” keyword before a function in a class - JavaScript?
- Why avoid increment (“++”) and decrement (“--”) operators in JavaScript?
- Inline conditions in Lua (a == b ? “yes” : “no”)
- C++ Program to Print “Even” or “Odd” without using conditional statement
- C Program to print “Even” or “Odd” without using Conditional statement
- C# Exponential (“E”) Format Specifier
Advertisements