LearnFrenzy
Sign in Take a free test

Functions · Find the Error · Question 4

C23 error: int area(); called with arguments Answer, explanation & discussion

  • Find the error
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 4 Back to Exercise

This program compiled (with warnings) as C17. Why does it fail to compile as C23?

main.c
#include <stdio.h>

int area();

int main(void) {
    printf("%d\n", area(3, 4));
    return 0;
}

int area(int w, int h) {
    return w * h;
}
  • A C23 removed the * operator for ints
  • B In C23 int area(); means area takes no parameters, so area(3, 4) and the later definition conflict with it Correct
  • C printf() needs %ld in C23
  • D main() must come last in C23
Correct Answer: Option B

Before C23 empty parentheses meant "parameters unknown", so the call went unchecked. C23 treats them as (void). Write the full prototype: int area(int w, int h);.

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.

Popular