LearnFrenzy
Sign in Take a free test

Variable Number of Arguments · Find the Error · Question 2

Error: ellipsis before a named parameter 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 <stdarg.h>
#include <stdio.h>

int sum(..., int count) {
    return count;
}

int main(void) {
    printf("%d\n", sum(1, 2, 3));
    return 0;
}
  • A count must be unsigned
  • B sum must use va_list
  • C There is no bug
  • D The ellipsis must be the last thing in the parameter list; named parameters come before it Correct
Correct Answer: Option D

Write int sum(int count, ...) and call it as sum(3, 1, 2, 3).

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