char letter ='A';
下面的程式使用了一個 char 變數和若干字元常數://This program uses a char variable and several character literals. #include <iostream> using namespace std; int main() { char letter; letter = 'A'; cout << letter << endl; letter = 'B'; cout << letter << endl; return 0; }程式輸出結果:
A
B
// This program demonstrates that characters are actually // stored internally by their ASCII integer value. #include <iostream> using namespace std; int main() { char letter; letter = 65; // 65 is the ASCII code for the character A cout << letter << endl; letter = 66; // 66 is the ASCII code for the character B cout << letter << endl; return 0; }程式輸出結果:
A
B