LearnFrenzy
Sign in Take a free test

C Const · Predict the Output · Question 8

A #define inside a function ignores scope – output Answer, explanation & discussion

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

What is the output of the following C program?

main.c
#include <stdio.h>

void setup(void) {
#define LIMIT 10
}

int main(void) {
    setup();
    printf("%d\n", LIMIT);
    return 0;
}
  • A 10 Correct
  • B Compilation error: LIMIT is not in scope
  • C 0
  • D Garbage
Correct Answer: Option A

The preprocessor runs before the compiler knows about functions or blocks. A macro is defined from its #define line to the end of the file (or an #undef), wherever that line is.

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