+ 1

C - Why can't you get address of a register variable?

Why does this code fail at p = &x ? #include <stdio.h> int main() { register int x = 4; int* p; p = &x; x++; printf("%d",*p); return 0; }

28th Dec 2019, 9:11 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
1 Answer
+ 6
Because registers are build into the cpu, they don't have an address. https://en.wikipedia.org/wiki/Processor_register
28th Dec 2019, 10:15 PM
Dennis
Dennis - avatar