LearnFrenzy
Sign in Take a free test

Declarations and Initializations · Find the Error · Question 2

Error: redeclaring a variable with a different type Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 2 Back to Exercise

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

main.c
#include <stdio.h>

int count;
double count;

int main(void) {
    printf("%d\n", (int) count);
    return 0;
}
  • A Globals cannot be redeclared
  • B The two declarations of count give it conflicting types Correct
  • C count must be initialised
  • D There is no bug
Correct Answer: Option B

Repeated declarations must agree on the type. Here one says int and the other double, so the compiler reports "redefinition with a different type". Use two different names.

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