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.

CategoryStorage-class specifiers
KindKeyword / Statement
C standardC89 / 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 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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏