实际上,我想知道如何将数组值用于另一个数组的大小声明。我有这个测试代码:
main(){
int sz[3]={1,2,3};
int track1[ sz[0] ]={111};
int track2[ sz[1] ]={222,222};
int track3[ sz[2] ]={333,333,333};
printf("%d %d %d\n", track1[0],track2[1],track3[2]);
}
这些是我得到的警告和错误:
test2.c: In function ‘main’:
test2.c:4: error: variable-sized object may not be initialized
test2.c:4: warning: excess elements in array initializer
test2.c:4: warning: (near initialization for ‘track1’)
test2.c:5: error: variable-sized object may not be initialized
test2.c:5: warning: excess elements in array initializer
test2.c:5: warning: (near initialization for ‘track2’)
test2.c:5: warning: excess elements in array initializer
test2.c:5: warning: (near initialization for ‘track2’)
test2.c:6: error: variable-sized object may not be initialized
test2.c:6: warning: excess elements in array initializer
test2.c:6: warning: (near initialization for ‘track3’)
test2.c:6: warning: excess elements in array initializer
test2.c:6: warning: (near initialization for ‘track3’)
test2.c:6: warning: excess elements in array initializer
test2.c:6: warning: (near initialization for ‘track3’)
test2.c:8: warning: incompatible implicit declaration of built-in function ‘printf’
这里有什么问题,而且我尝试过,这甚至可能吗?