What will be the output of the following C++ code snippet ?
#include <iostream>
using namespace std;
int main() {
register int i = 1;
int *ptr = &i;
cout << *ptr;
return 0;
}
Please first select an option.
The correct answer is C) Compiler error
The register keyword is used to suggest to the compiler to store the variable i in a register for faster access. However, the register keyword is merely a suggestion to the compiler, and the compiler can choose to ignore it if it deems necessary. Using & on a register variable may be incorrect because the compiler may place the variable in a register and determining its address is unlawful.