-5

Is the below declaration valid in C?

char key[] = {};

If not why not?

6
  • 1
    How big would the array be? Commented Jul 20, 2016 at 16:44
  • I see two completely separate questions above. Suggest picking one. Commented Jul 20, 2016 at 16:45
  • I have chosen one and array can be of any size Commented Jul 20, 2016 at 16:48
  • 1
    Have you actually tried it? Commented Jul 20, 2016 at 17:02
  • 1
    An initializer cannot be empty in C Commented Jul 20, 2016 at 17:17

1 Answer 1

1

Per the online C2011 standard, it is not valid; you may not have an empty initializer list (see 6.7.9, Syntax). That doesn't mean a specific implementation can't offer an empty initializer list as an extension, but the utility would be unclear.

Beyond that, the compiler has no way of knowing how much storage to set aside for the array.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.