網(wǎng)頁提示正確但是輸出卻沒結(jié)果?
#include <stdio.h>
int main()
{
??? //第一種形式
??? int arrFirst[3] = {1,2,3};
??? //第二種形式
??? int arrSecond[] = {1,2,3};
??? //第三種形式
??? int arrThird[3];
??? //給arrThird數(shù)組每個元素初始化
??? int arrThird[0] = 1;
??? int arrThird[1] = 2;
??? int arrThird[2] = 3;
??? //輸出第一個數(shù)組中的第二個元素
??? printf("%d\n", arrFirst[1]);
??? //輸出第二個數(shù)組中的第二個元素
??? printf("%d\n", arrSecond[1]);
??? //輸出第三個數(shù)組中的第二個元素
??? printf("%d\n", arrThird[1]);
??? return 0;
}
這是我的代碼,然后輸出是這樣的:
hello.c: In function 'main':
hello.c:11:9: error: conflicting types for 'arrThird'
? ? int arrThird[0] = 1;
? ? ? ? ^
hello.c:9:9: note: previous declaration of 'arrThird' was here
? ? int arrThird[3];
? ? ? ? ^
hello.c:11:5: error: invalid initializer
? ? int arrThird[0] = 1;
? ? ^
hello.c:12:9: error: conflicting types for 'arrThird'
? ? int arrThird[1] = 2;
? ? ? ? ^
hello.c:11:9: note: previous definition of 'arrThird' was here
? ? int arrThird[0] = 1;
? ? ? ? ^
hello.c:12:5: error: invalid initializer
? ? int arrThird[1] = 2;
? ? ^
hello.c:13:9: error: conflicting types for 'arrThird'
? ? int arrThird[2] = 3;
? ? ? ? ^
hello.c:12:9: note: previous definition of 'arrThird' was here
? ? int arrThird[1] = 2;
? ? ? ? ^
hello.c:13:5: error: invalid initializer
? ? int arrThird[2] = 3;
? ? ^
這是怎么回事?是我的代碼整個都錯了嗎
2017-12-30
arrThird數(shù)組,初始化不用定義類型,去掉就好。int arrThird[3]; arrThird[0] = 1;arrThird[1] = 2;arrThird[2] = 3; ?前邊的int都去掉 。因?yàn)槟阋呀?jīng)定義了int類型的數(shù)組,數(shù)組里面的類型就都是int類型,不用重新定義。
2017-08-21
在線的運(yùn)行結(jié)果都不是很準(zhǔn)確,還是建議你下一個VS,是免費(fèi)的