惡搞嘻語言第二嘻:嘻資料


若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

C 語言中,宣告一個變數的語法為:
變數型態  變數1, 變數2, ...., 變數n;
詳細的教學可參考底下兩個網頁:

#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#include<stdint.h>

intmain(void) {
// 有號整數
shortsht; // -32768->32767
inti; // -32768->32767
longl; // -2147483648->2147483647

// 無號整數
unsignedshortusht;
unsignedintui;
unsignedlongul;

// 浮點數
floatf; // 單精準度
doubled; // 雙精準度

// 字元,請參考 http://www.asciitable.com/
charc = 'a';
c = 97;

printf("型態\t\t大小(bytes\n");
printf("short\t\t%d\n", sizeof(short));
printf("int\t\t%d\n", sizeof(int));
printf("long\t\t%d\n", sizeof(long));
printf("float\t\t%d\n", sizeof(float));
printf("double\t\t%d\n", sizeof(double));
printf("long double\t%d\n", sizeof(longdouble));
printf("char\t\t%d\n", sizeof(char));

// 請參考 http://www.cplusplus.com/reference/climits/
// http://edisonx.pixnet.net/blog/post/35305668-%5Bc%5D-printf-%E5%BC%95%E6%95%B8%E8%AA%AA%E6%98%8E
printf("SHRT_MIN = %d\n", SHRT_MIN);
printf("SHRT_MAX = %d\n", SHRT_MAX);
printf("USHRT_MAX = %d\n", USHRT_MAX);

printf("INT_MIN = %d\n", INT_MIN);
printf("INT_MAX = %d\n", INT_MAX);
printf("UINT_MAX = %u\n", UINT_MAX);

printf("LONG_MIN = %ld\n", LONG_MIN);
printf("LONG_MAX = %ld\n", LONG_MAX);
printf("ULONG_MAX = %lu\n", ULONG_MAX);
printf("LLONG_MAX = %lld\n", LLONG_MAX);
printf("LLONG_MIN = %lld\n", LLONG_MIN);
printf("ULLONG_MAX = %llu\n", ULLONG_MAX);

system("pause"); // Console 視窗等待使用者輸入鍵盤上的任意按鍵
return0;
}


沒有留言: