基本型別

int bool char float

變數

/*
 * example
*/
#include <bits/stdc++.h>
using namespace std;

void int_family() { // 整數
    short b = 20; // 2 bytes +- 1e4
    int a = 10; // 4 bytes +- 1e9
    long long c = 40; // 8 bytes +- 1e18
    // ---------------------
    long d = 30; // 有的跟[int]一樣 有的跟[ long long ]一樣
}

void char_family() { // 字元
    char c = 'A'; // 1 byte +- 1e2
    string s = "Hello"; // char[]
}

void float_family() { // 小數
    float e = 5.5f; // 4 bytes +- 1e38
    double f = 6.5; // 8 bytes +- 1e308
    long double g = 7.5; // 16 bytes +- 1e4932
}

void bool_family(){ 
    bool isOk = true; // 1 byte 0 or 1
}

int main() {
    int_family();
    char_family();
    float_family();
    bool_family();
    return 0;
}

陣列

/*
 * example
*/
#include<bits/stdc++.h>
using namespace std;

int main(){
    int a[100]; // 0~99
    for(int i=0;i<n;i++){
        a[i] = i;
    }
    return 0;
}

Last updated

Was this helpful?