register Register storage hint
register Register storage hint
register suggests registers for locals, without a guarantee. It forbids & and file scope; compilers decide, so the address constraint is its main use.
| Category | Storage-class specifiers |
|---|---|
| Kind | Keyword / Statement |
| C standard | C89 / C90 |
📝 Syntax
register int counter = 0;
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
sum = 6
🏷️ Related storage-class specifiers
📚 Related Tutorials
❓ FAQ
QWhy can't the address-of operator be used on a register variable?
AThe standard forbids applying unary & to an object declared with register, whether or not the compiler actually assigns it to a register. A pointer cannot be used to bypass this semantic restriction.
QCan register still make a program faster?
AThere is no guarantee. Modern compilers allocate registers using data flow and calling conventions, so register is usually an ignorable hint. Its main remaining use is to express that the object's address cannot be taken.
QCan register be used for a function parameter?
AYes. A parameter declared with register has automatic storage duration and carries the register suggestion. Its address still cannot be taken inside the function, and register remains invalid at file scope.