user3656667
user3656667

Reputation: 13

Initialize array of strings with \0

I would like to initialize an array of strings with \0. Is it right to do it like this?

char first[1024][1024] = {'\0'};

Upvotes: 0

Views: 262

Answers (2)

David Ranieri
David Ranieri

Reputation: 41017

For a 2d array is better to use:

char first[1024][1024] = {{'\0'},{'\0'}};

or better yet (as suggested by @haccks):

char first[1024][1024] = {{'\0'}};

in order to avoid warnings.

Upvotes: 2

ACcreator
ACcreator

Reputation: 1372

If it is a static array, say, a global array, you do not need to do any initialization and the values of the array are set to 0 by default.

Upvotes: -1

Related Questions