Recall & Review
beginner
What is the purpose of the <code>register</code> storage class in C?The <code>register</code> storage class suggests to the compiler to store the variable in a CPU register for faster access instead of RAM.Click to reveal answer
beginner
Can you take the address of a variable declared with
register?No, you cannot use the address-of operator (
&) on a register variable because it may be stored in a CPU register, which does not have a memory address.Click to reveal answer
intermediate
How does the
register keyword affect variable scope and lifetime?The
register keyword does not change the scope or lifetime of a variable. It only suggests faster storage. The variable still has automatic storage duration and block scope.Click to reveal answer
beginner
Example: <br>
register int count = 0;<br>for (int i = 0; i < 10; i++) {<br> count += i;<br>}<br>What does register do here?It suggests the compiler to keep
count in a CPU register for faster updates during the loop, improving performance.Click to reveal answer
intermediate
Is the
register keyword mandatory for faster variables?No, modern compilers optimize variable storage automatically. The
register keyword is mostly ignored but can still be used as a hint.Click to reveal answer
What does the
register keyword in C suggest to the compiler?✗ Incorrect
The
register keyword suggests storing the variable in a CPU register to speed up access.Can you use the address-of operator (
&) on a register variable?✗ Incorrect
You cannot take the address of a
register variable because it may not have a memory address.Which of these is true about
register variables?✗ Incorrect
register variables have automatic storage duration like normal local variables.Does the
register keyword guarantee the variable will be stored in a CPU register?✗ Incorrect
The
register keyword is a hint; the compiler may ignore it.Why might modern compilers ignore the
register keyword?✗ Incorrect
Modern compilers decide the best storage automatically, so
register is often ignored.Explain what the
register storage class does in C and its limitations.Think about speed and memory address.
You got /4 concepts.
Describe a situation where using
register might improve program performance.Consider counting or accumulating inside a loop.
You got /3 concepts.