C program example:
- #include <stdio.h>
- int main () {
- register int a=5;
- printf("The value of a is %d", a);
- return 0;
- }
In this example by using register keyword, you can access the data quickly. When using this keyword you're asking the compiler to save the variable a in the processor's register. I should also mention that printf is also used to output on the terminal and %d is used to set a decimal in this place (a because it's an integer number).
You can also add address to the memory location by using a pointer variable. Here comes an example:
- #include <stdio.h>
- int main()
- {
- int i = 10;
- register int *a = &i;
- printf("%d", *a);
- getchar();
- return 0;
- }
After saving the value of i inside the CPU's register, a pointer is set to get the address of the memory location where the variable i is set. For instance, when you run the program you'll see the address referenced by the pointer a.
No comments:
Post a Comment