Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When initializing a char array, is the remaining space zero filled or uninitialized?

Tags:

c

Given

char foo[1024] = "bar";

This will initialize foo to contain 'b','a','r',0 . Is the remaining 1020 characters zero initialized, or uninitialized ?

I'd think the above is the same as `char foo[1024] = {'b','a','r','\0'} ; and as with initializing of aggregates, any member not mentioned is initialized to zero ?

like image 500
Habalusa Avatar asked Jan 04 '11 13:01

Habalusa


1 Answers

If an array/aggregate is initialized somehow[edit: by use of a static initializer], the remaining unspecified entries are zeroed, yes.

like image 156
user562374 Avatar answered Oct 18 '22 23:10

user562374