1

How does the initialization happen in cases 2, 3, 4, 5 below. 1 will contain garbage.

char x[16];
char x[16] = {0};
char x[16] = {0, };
char x[16] = {1};
char x[16] = {1, };

2 Answers 2

7

If you use the brace initializer syntax with arrays, any additional elements not mentioned in the initializer list are initialized with zeros.

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

1 Comment

Note that C++ allows "char c[16] = {};" to fill everything with zeros.
4

@Philipp is correct.

A quick test gave me this:

http://codepad.org/DsOtXIYg

btw that's a great link for running test code.

2 Comments

Hi! Welcome to StackOverflow. This should be a comment. Please read the FAQ.
I did not have 50 rep to add a comment to someone else's post, but now I have :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.