C语言结构中使用数组

#include "stdio.h"
struct People
{
    int age;
    int arr[3];//这里如果不指定数组大小,在turboc中编译不能通过,但在vs2008中可以
};

void main()
{
    struct People m={3,{4,5,6}};
    struct People p,p2;
    p.age=9;
    p2=p;
    p2.age=456;
    
    printf("%d\n",p.age);

    printf("%d\n",m.arr[2]);

    //在vs2008中,如果上面的结构定义时不指定数组元素的大小,则sizeof(People)为4

    printf("%d\n",sizeof(People)); 

}

原文地址:https://www.cnblogs.com/mxw09/p/1834921.html