不重要 11 發表於 September 28, 2010 檢舉 Share 發表於 September 28, 2010 type coercion和type casting是什麼意思他們兩個有什麼差別??? 鏈接文章 分享到其他網站
j100002ben 10 發表於 September 29, 2010 檢舉 Share 發表於 September 29, 2010 (已編輯) type coercionImplicit type conversion, also known as coercion, is an automatic type conversion by the compiler.double d;long l;int i; if (d > i) d = i;if (i > l) l = i;if (d == l) d *= 2;type castingExplicit type conversion is a type conversion which is explicitly defined within a program (instead of being done by a compiler for implicit type conversion).double da = 5.5;double db = 5.5;int result = (int)da + (int)db;//Result would be equal to 10 instead of 11.說白話就是一個編譯器會幫你自動轉換資料型態...另外一個是你自己強制轉換...P.S.:剛剛在找這兩個東西的資料的時候一直google到這一篇主題XDDDDDD 此內容已被編輯, September 29, 2010 ,由 j100002ben 鏈接文章 分享到其他網站
不重要 11 發表於 September 30, 2010 作者 檢舉 Share 發表於 September 30, 2010 那type coercion的意是就是d可以從double變成int或long??? 鏈接文章 分享到其他網站
j100002ben 10 發表於 September 30, 2010 檢舉 Share 發表於 September 30, 2010 (已編輯) 那type coercion的意是就是d可以從double變成int或long???type coercion的意思是說~~編譯器會用他自己的邏輯去判斷需要作資料型態轉換的部份像是如果a = 1if(a)會是truea = 100if(a)還是true雖然 bool型態和int型態是不一樣的不過他們可以再這邊使用的原因就是因為編譯器和你處理掉了..另外一個例子是C語言的char 和short int他們也是可以互相轉換的~~再來看看錢一個回覆的例子double da = 5.5;double db = 5.5;如果是type coercionint result = da + db;// =5.5+5.5 = 11不過如果使用強制cast轉換int result = (int)da + (int)db;// = 5 + 5 = 10 此內容已被編輯, September 30, 2010 ,由 j100002ben 鏈接文章 分享到其他網站
Recommended Posts