C中的“注册”关键字

寄存器变量告诉编译器将变量存储在CPU寄存器中而不是内存中。常用变量保存在寄存器中,并且具有更快的可访问性。我们永远无法获得这些变量的地址。“ register”关键字用于声明寄存器变量。

范围-它们在功能本地。

默认值-默认初始化值为垃圾值。

生命周期-直到在其定义的块的执行结束。

这是C语言中的注册变量示例,

示例

#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;
}

输出结果

The value of register variable b : S
The sum of auto and register variable : 18

Register关键字也可以与指针一起使用。它可以具有内存位置的地址。它不会产生任何错误。

这是C语言中的register关键字示例

示例

#include<stdio.h>
int main() {
   int i = 10;
   register int *a = &i;
   printf("The value of pointer : %d", *a);
   getchar();
   return 0;
}

输出结果

The value of pointer : 10