LearnFrenzy
Sign in Take a free test

Declarations and Initializations · Predict the Output · Question 10

Repeated tentative definitions at file scope Answer, explanation & discussion

  • Output
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 10 Back to Exercise

What is the output of the following C program on a 64-bit system?

main.c
#include <stdio.h>

int count;
int count;
int count = 5;

int main(void) {
    printf("%d\n", count);
    return 0;
}
  • A 5 Correct
  • B 0
  • C Compilation error: redefinition
  • D Garbage
Correct Answer: Option A

A file-scope declaration without an initializer is a tentative definition and may be repeated. With an initializer it is the real definition, so count is 5. Two initialised definitions would be an error.

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