C99标准中的部分新特性

我有点怀疑我会不会C语言了。

 

1、变长数组(VLA)

int n = 0;
scanf("%d", &n);
int arr[n];

2、数组初始化

int arr[10] = {[0] = 1, [5] = 6, [9] = 10};
for(int i = 0; i < 10; i++) {
    printf("%d\n", arr[i]);
}

3、结构体初始化

struct Struct {
    int a;
    int b;
    int c;
};
struct Struct test = {.b = 10, .c = 20};
printf("%d %d %d\n", test.a, test.b, test.c);

 

这些代码在支持C99的编译器都可以通过,也许需要编译参数,比如gcc可能需要“-std=c99”

posted @ 2014-10-14 14:13  Anti-Magic  阅读(251)  评论(0编辑  收藏  举报