码迷,mamicode.com
首页 > 编程语言 > 详细

c语言变长数组

时间:2020-03-17 08:13:17      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:cores   turn   ++   pthread   info   sizeof   数组   变长数组   scores   

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <time.h>
#include <unistd.h>

typedef struct score_s{
    char name[20];
    int scores[0];
}score;


int main() {
    score *scoreInfo = malloc(sizeof(score) + sizeof(int) * 3);
    strcpy(scoreInfo->name, "guanxianseng");
    scoreInfo->scores[0] = 100;
    scoreInfo->scores[1] = 110;
    scoreInfo->scores[2] = 120;
    printf("name:%s\n", scoreInfo->name);
    for (int i = 0; i < 3; i++) {
        printf("score:%d\t", scoreInfo->scores[i]);
    }
    printf("\n");

    return 0;
}

 

c语言变长数组

标签:cores   turn   ++   pthread   info   sizeof   数组   变长数组   scores   

原文地址:https://www.cnblogs.com/luckygxf/p/12508226.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!