+ 3
Why does arrays in c have none zero initial value to some elements?
4 Respostas
+ 6
C was designed to be as close to assembler as possible while giving higher level language convenience. Therefore, everything is under your control. No point zeroing memory, if the code proceeds to put other values in it. But, as rodwynnejones pointed out it is simple to do so, if you want it.
+ 3
when you create an array it holds base address.and it allocate memory in sequential order.when an array is not initialized it contains garbage value(unknown value).to avoid this type of problems we need to initialize array values to zero.
for example;
int arr[256]={0};
here all array values are initialized to zero
anther example is,
int arr[5]={1,2,3};
here we declare first 3 elements and the remaining elements automatically assigned to zero.
+ 2
you need to do this:-
int arr[256] = {0};