Register keyword in C.
Hello coders! Welcome back!
Today we are going to peep into register keyword used in C. Before that let's look into memory accessing hierarchy.
Image source- click here
We can see that the order in which the compiler accesses the memory.
Register memory size is small and can be accessed easily. Whereas if you see magnetic tapes have larger size but while accessing it consumes time.
Now we got to know that register memory is easy to access, let's look into the syntax-
register <data_type> <varriable_name>;
example-
By mentioning 'register' we are telling the compiler to store the variable in register memory.
Since we know that access time required for register memory is less, its recommended to declare as register for the variables that are frequently used in the program.
The compiler doesn't assure you that it is going to allocate register memory even if you declare it as register. It's compiler choice. It is going to decide whether to allocate it or not.
Complier themself are optimized means even if we don't declare a variable as register and that variable is frequently used in the program then compiler automatically places it in register memory, so that access time is reduced.
So that it for this blog!! I hope so you got to know what is register keyword in C. If any doubts drop a comment.
Happy learning!
Today we are going to peep into register keyword used in C. Before that let's look into memory accessing hierarchy.
Image source- click here
We can see that the order in which the compiler accesses the memory.
Register memory size is small and can be accessed easily. Whereas if you see magnetic tapes have larger size but while accessing it consumes time.
Now we got to know that register memory is easy to access, let's look into the syntax-
register <data_type> <varriable_name>;
example-
By mentioning 'register' we are telling the compiler to store the variable in register memory.
Since we know that access time required for register memory is less, its recommended to declare as register for the variables that are frequently used in the program.
The compiler doesn't assure you that it is going to allocate register memory even if you declare it as register. It's compiler choice. It is going to decide whether to allocate it or not.
Complier themself are optimized means even if we don't declare a variable as register and that variable is frequently used in the program then compiler automatically places it in register memory, so that access time is reduced.
So that it for this blog!! I hope so you got to know what is register keyword in C. If any doubts drop a comment.
Happy learning!
Comments
Post a Comment