简体   繁体   English

如何初始化结构指针数组?

[英]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?? 我可以将所有它们初始化为NULL,如下所示?

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 一个NULL(或一个0)就足够了,因为0在分配给指针时被转换为NULL

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

additional info: first element will be initialized to the first value supplied. 附加信息:第一个元素将初始化为提供的第一个值。 rest will get 0 according to standards. 根据标准,休息将获得0分。 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 . 为每个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};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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