I was implementing Radix Sort which required array of pointer and to avoid segmentation fault I have to initialize it to NULL.
When I tried : struct Node *Bucket[10] = NULL
But it gives :error: invalid initializer
So , my teacher suggested : struct Node *Bucket[10] = {0}
So my question is what is the difference between {0} and NULL and I have also tried :
struct Node *Bucket[10] ;
for(int i=0 ; i<10 ; i++)
{
Bucket[i] = NULL ;
}
How {0} is same this for loop
Edit 1:
There is an additional question why are we making Bucket[0] .. Bucket[9] as NULL and how does it prevent segmentation fault.
void Radix_Sort(int *Arr)
{
int max ;
max = Max_element_in_array(Arr);
struct Node *Bucket[10] = {0} ;
for(int exp = 1 ; max / exp > 0 ; exp*=10)
{
int k=0 ;
for(int i=begin ; i<end ; i++)
{
Append_a_linked_list(&Bucket[(Arr[i]/exp)%10],Arr[i]);
}
for(int j=0 ; j<10 ; j++)
{
while( Bucket[j] )
{
Arr[k++] = Delete_first_node(&Bucket[j]);
}
}
}
}