While reading Keywords That Aren't (or, Comments by Another Name) by Herb Sutter I came across these lines:
That's right, some keywords are semantically equivalent to whitespace, a glorified comment.
And
We've seen why the C++ language treats keywords as reserved words, and we've seen two keywords —auto and register — that make no semantic difference whatsoever to a C++ program. Don't use them; they're just whitespace anyway, and there are faster ways to type whitespace.
If the keywords like auto(maybe not in C++11) and register are of no value, then why were they created and used?
If it doesn't make any difference to include the register before a variable
#include<stdio.h>
int main(){
register int a = 15;
printf("%d\n%d\n",&a,a);
return 0;
}
Why does the above program give an error?
test_register.c: In function ‘main’:
test_register.c:4:2: error: address of register variable ‘a’ requested
printf("%d\n%d\n",&a,a);
The following program works in C++.
#include<iostream>
int main(){
register int a = 15;
std::cout<<&a<<'\n'<<a;
return 0;
}