I've an array of pointers to structure. Can i initialize all them to NULL as below??
struct hash
{
int bid;
struct hash *prev,*next,*fl,*fr;
};
struct hash *h[4]={NULL,NULL,NULL,NULL};
I've an array of pointers to structure. Can i initialize all them to NULL as below??
struct hash
{
int bid;
struct hash *prev,*next,*fl,*fr;
};
struct hash *h[4]={NULL,NULL,NULL,NULL};
one NULL (or one 0) will be enough since 0 is converted to NULL when assigned to pointers
struct hash *h[4] = {0};
additional info: first element will be initialized to the first value supplied. rest will get 0 according to standards. which part, section of standards? i have no idea but you can find it somewhere in the standards.
C11 6.7.9.19 says: all subobjects that are not initialized explicitly shall be initialized implicitly the same as objects that have static storage duration. and earlier in 6.7.9.10 says: If an object that has static or thread storage duration is not initialized explicitly, then: — if it has pointer type, it is initialized to a null pointer; — if it has arithmetic type, it is initialized to (positive or unsigned) zero; ...I think it will work
int main()
{
struct hash
{
int bid;
struct hash *prev,*next,*fl,*fr;
};
struct hash *h[5]={0};