Home > Backend Development > C++ > body text

In C language, what is the register storage class?

WBOY
Release: 2023-08-30 09:45:15
forward
1369 people have browsed it

In C language, what is the register storage class?

There are four storage classes in the C programming language, which are:

  • auto
  • extern
  • static
  • register

Register variable

  • The keyword is register.

  • The value of a register variable is stored in the CPU's register, not in memory, as ordinary variables are stored in memory.

  • Register is a temporary storage unit in the CPU.

  • They allow register variables to have faster access times than ordinary variables.

Example 1

The following is the register storage class of the C program:

Demonstration

#include<stdio.h>
main ( ){
   register int i;
   for (i=1; i<=5; i++)
      printf ("%d ",i);
}
Copy after login

Output

The output is stated below −

1 2 3 4 5
Copy after login

Example 2

Consider another C program that uses the register storage class−

Online demonstration

#include<stdio.h>
int main(){
   register int a;
   printf("%d",a); //prints default value of a =0
}
Copy after login

Output

The output is stated below −

0
Copy after login

Example 3

The 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);
}
Copy after login

Output

The output is stated below −

Error:add of reg var?
Copy after login

The above is the detailed content of In C language, what is the register storage class?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!