c语言变长数组

#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;
}

 

posted on 2020-03-17 00:51  luckygxf  阅读(663)  评论(0编辑  收藏  举报

导航