the code ->
int a[10]={0};
initializes all elements of a to 0, but when i do this ->
int a[10]={0,1}
the contents of the array are as follows : 0 1 0 0 0 0 0 0 0 0
how??
the code ->
int a[10]={0};
initializes all elements of a to 0, but when i do this ->
int a[10]={0,1}
the contents of the array are as follows : 0 1 0 0 0 0 0 0 0 0
how??
How? Up to the compiler.
The question you probably intended to ask is better expressed as "Why?". The answer to that is : because the standard says so. Essentially, in the declaration
the first two elements are initialised as 0 and 1 respectively. For auto arrays (eg local to a function, without the static qualifier) the remaining elements are initialised as they would have been if the array was static. And, if the array was static, those elements would be initialised to zero.Code:int a[10] = {0, 1};
What else were you expecting?
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010