Topic : 對編譯系統默認的data type轉換,也要有充分的認識。
Description : None
Example : /* #include<stdio.h> /* Using type cast to make sure the difference between types */ unsigned int i; i = 1234567; int main(int argc, char* argv[]){
基本上這的sample是在要求當型別轉換(type casting)時,要把強制轉換寫上去,確保 programmer知道這是他要的。
* sample-63
*
* This sample shows the important of type conversions.
*
* Explicit type conversion can be forced ("coerced") in
* any expression, with a unary operator called a cast.
*
* (type-name) expression
*
* Always remember use type conversion between different
* types variable assignment to avoid ambiguous.
*/
void typeCast(){
unsigned short int exam;
printf("sizeof(unsigned int) : %d\n", sizeof(unsigned int));
printf("i : %#x\n", i);
printf("i : %d\n", i);
exam = (unsigned short int)i;
printf("sizeof(unsigned short int) : %d\n", sizeof(unsigned short int));
printf("exam : %#x\n", exam);
printf("exam : %d\n", exam);
}
typeCast();
return 0;
}
沒有留言:
張貼留言