ProgrammingModerateWipro · Capgemini
Which of these is NOT allowed for a variable declared with the register storage class in C?
- A. Initialising it in its declaration
- B. Taking its address with &
- C. Declaring it inside a nested block
- D. Using it as a loop counter
Correct answer: B. Taking its address with &
register is a hint that the variable may live in a CPU register, which has no memory address, so applying & to it is a constraint violation in C (whether or not the compiler uses a register). Everything else an automatic variable can do is allowed.
More C Programming questions
- What does p(5) print? c void p(int n) { if (n <= 0) return; p(n - 2); printf("%d", n); p(n - 3); }
- Which statement about this C declaration is true? c char a[5] = "hello";
- What is printed? c #define CUBE(x) ((x) (x) (x)) int n = 0; int f(void) { n++; return 2; } int main(void) { int r = CUBE(f()); printf("%d…
- What is printed? c unsigned char rotl(unsigned char v, int k) { return (unsigned char)(v << k | v >> (8 - k)); } int main(void) {…
- With int a[3], p = a; which statement fails to compile?
- Assume 4-byte int. What is printed? c struct Msg { int len; char data[]; }; struct Msg m = malloc(sizeof m + 10); printf("%zu", sizeof m);