struct结构体成员变量赋值

struct成员赋值方法

  • 常见的方法就不说明了!
  • 下面介绍三种方式

1.第一种:

#include <stdio.h>

struct test
{
    int a;
    int b;
};

int main(int argc, char** argv)
{
    struct test node = {
                   node.a= 1,
                   node.b= 2
                };
    /**
     struct test node = {
                   .a= 1,
                   .b= 2
                };
    */
    printf("%d", node.a);
    return 0;
}


  1. 第二种:
    struct test node = {
                   a: 1,
                   b: 2
                };

  1. 第三种:
  struct test node = {
                   1,
                   2
                };
原文地址:https://www.cnblogs.com/cwhan/p/14710526.html