LearnFrenzy
Sign in Take a free test

C Variables · Find the Error · Question 5

Error: taking the address of a register variable Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 5 Back to Exercise

The program below has a bug. Which statement correctly describes it?

main.c
#include <stdio.h>

int main(void) {
    register int n = 10;
    int *p = &n;
    printf("%d\n", *p);
    return 0;
}
  • A register variables cannot be initialised
  • B The address of a register variable cannot be taken Correct
  • C p must be a register pointer
  • D There is no bug
Correct Answer: Option B

Even though compilers ignore the register hint for code generation, the language still forbids & on such a variable. Drop register – it brings no speed today.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links