Commit 61aaaab2 authored by Administrator's avatar Administrator
Browse files

added variable basic types

parent c07154f1
#include <iostream>
#include <stdio.h>
using namespace std;
// main() 是程序开始执行的地方
int main(){
// 起始行
cout << "---------------------------------" << endl;
cout << "Size of char : " << sizeof(char) << endl;
cout << "Size of int : " << sizeof(int) << endl;
cout << "Size of short int : " << sizeof(short int) << endl;
cout << "Size of long int : " << sizeof(long int) << endl;
cout << "Size of float : " << sizeof(float) << endl;
cout << "Size of double : " << sizeof(double) << endl;
cout << "Size of wchar_t : " << sizeof(wchar_t) << endl;
cout << "---------------------------------" << endl;
/********************************************
* 布尔型 1 个字节
* 0 或者 1
*******************************************/
bool true_or_false;
true_or_false = true;
if (true_or_false) {
// Output 01
cout << "Output 01 | True (" << true_or_false << ")" << endl;
}
true_or_false = false;
if (!true_or_false) {
// Output 02
cout << "Output 02 | False (" << true_or_false << ")" << endl;
}
/********************************************
* 字符型 1 个字节
* char : -128 到 127 或者 0 到 255
* unsigned char : 0 到 255
*******************************************/
char char_min, char_max, char_A, char_overflow;
char_min = int(0);
char_max = int(255);
char_A = int(65);
// char_overflow = int(256); // 将会产生数值溢出错误
// Output 03
cout << "Output 03 | Char Min is " << char_min << " (" << int(char_min) << ")" << endl;
cout << "Output 04 | Char Max is " << char_max << " (" << int(char_max) << ")" << endl;
cout << "Output 05 | Char A is " << char_A << " (" << int(char_A) << ")" << endl;
// cout << "Output 05 | Char Overflow is " << char_overflow << " (" << int(char_overflow) << ")" << endl;
/********************************************
* 自定义类型
* 使用 typedef 为一个已有的类型取一个新的名字
*******************************************/
typedef int feet;
feet distance;
distance = 123;
cout << "Output 06 | distance is " << distance << endl;
/********************************************
* 枚举类型
*******************************************/
enum color { red, green, blue } c;
c = green;
cout << "Output 07 | Enum c is " << c << endl;
// 结束行
cout << "---------------------------------" << endl;
return 0;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment