LearnFrenzy
Sign in Take a free test

Complicated Declarations · Find the Error · Question 1

Error: a function declared to return an array Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 1 Back to Exercise

The program below has a bug. Which statement correctly describes it?

main.c
#include <stdio.h>

int make(void)[3];

int main(void) {
    printf("ok\n");
    return 0;
}
  • A The array size must be a variable
  • B C functions cannot return arrays; return a pointer to an array (int (*make(void))[3]) or a struct that contains one Correct
  • C make needs a parameter
  • D There is no bug
Correct Answer: Option B

Arrays are not assignable values in C, so they cannot be returned. Wrapping the array in a struct is the usual way to return it by value.

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