
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
“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
",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 Articles
- The register storage class in C++
- ‘this’ keyword in C#
- abstract keyword in C#
- static keyword in C#
- volatile keyword in C#
- Final keyword in C#
- try keyword in C#
- return keyword in C#
- Static Keyword in C++
- “extern” keyword in C
- override Keyword in C++
- Restrict keyword in C
- Mutable keyword in C++?
- Generic keyword in C ?
- Finally keyword in C#

Advertisements