简体   繁体   中英

How to initialize array of pointers to structures?

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.

Yes!

T *t[] = {NULL, NULL};

Works for each T .

你也可以使用

struct hash *h[]={0,0,0,0};

I think it will work

int main()
{
  struct hash
  {
    int bid;
    struct hash *prev,*next,*fl,*fr;
  };
struct hash *h[5]={0};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM