- Trending Categories
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
What is a register storage class in C language?
There are four storage classes in C programming language, which are as follows −
- auto
- extern
- static
- register
Register variables
The keyword is register.
Register variable values are stored in CPU registers, rather than in memory where, normal variables are stored.
Registers are temporary storage units in CPU.
They allow faster access time for register variables than normal variables.
Example 1
Following is the C program for register storage class −
#include<stdio.h> main ( ){ register int i; for (i=1; i<=5; i++) printf ("%d ",i); }
Output
The output is stated below −
1 2 3 4 5
Example 2
Consider another C program for register storage class −
#include<stdio.h> int main(){ register int a; printf("%d",a); //prints default value of a =0 }
Output
The output is stated below −
0
Example 3
Following is the third C program for static storage class −
#include<stdio.h> int main(){ register int i = 10; int *p; //int *p = &i; //error occurred ,here we are trying to request address of register variable printf("Value of i: %d", *p); printf("Address of i: %u", p); }
Output
The output is stated below −
Error:add of reg var?
Advertisements