C 中auto decltype與陣列

2021-10-07 13:36:52 字數 533 閱讀 6384

auto與decltype都是c++11中新引入的型別說明符。

使用型別說明符auto,實際上就是讓編譯器來分析表示式所屬型別,所以auto定義的變數必須有初始值。

auto i = 1;
此時編譯器會推斷變數i的型別是int。

decltype的用法請參考《c++中decltype的使用方法》。

整型陣列a的定義如下:

int a = ;
使用auto與a來定義另外乙個變數

auto b(a);
此時編譯器將b的型別判斷為整型指標,所以可以有如下**

b = &a[1];
使用decltype與a來定義另外乙個變數

decltype(a) c;
此時編譯器將c的型別判斷為含有5個元素的整形陣列,所以可以有如下**

c[1] = a[1];

c 11 auto,decltype型別推導

auto型別推導 1.auto推導 auto x 5 被編譯器推導為int型別 auto pi new auto 1 編譯器推導為int const auto v x,u 5 v為 const int u為 const int static auto y 0.1 y為static const dou...

C與C 中的 問題

test.c include void change int a,int b,int c int main 執行 compiling.9.cd vcfile 9.c 4 error c2143 syntax error missing before d vcfile 9.c 4 error c214...

c與c 中struct區別

這裡有兩種情況下的區別。1 c的struct與c 的class的區別。2 c 中的struct和class的區別。在第一種情況下,struct與class有著非常明顯的區別。c是一種過程化的語言,struct只是作為一種複雜資料型別定義,struct中只能定義成員變數,不能定義成員函式 在純粹的c語...