LearnFrenzy
Sign in Take a free test

C Const · Predict the Output · Question 2

SQUARE(2 + 3) macro vs function – output Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 2 Back to Exercise

What is the output of the following C program?

main.c
#include <stdio.h>

#define SQUARE(x) x * x

static inline int square(int x) { return x * x; }

int main(void) {
    printf("%d %d\n", SQUARE(2 + 3), square(2 + 3));
    return 0;
}
  • A 11 25 Correct
  • B 25 25
  • C 11 11
  • D 25 11
Correct Answer: Option A

The macro pastes text: 2 + 3 * 2 + 3 = 11. The function receives the value 5 and returns 25. Macros need brackets everywhere – ((x) * (x)) – or, better, an inline function.

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