C++ / sizeof演算子

函数ではなく演算子なのでカッコでくくる必要はないがカッコでくくるのが慣例との由。

#include <iostream>
using namespace std;

int main(){
    int a[] = {0,1,2,3,4,5};
    cout << "int型排列aの全体のバイト数: " << sizeof(a) << endl;
    cout << "int型のバイト数: " << sizeof(int) << endl;
    cout << "だからこれが排列aの要素数: " << sizeof(a) / sizeof(int) << endl << endl;


    double b[] = {0,1,2,3,4,5};
    cout << "double型排列bの全体のバイト数: " << sizeof(b) << endl;
    cout << "double型のバイト数: " << sizeof(double) << endl;
    cout << "だからこれが排列bの要素数: " << sizeof(b) / sizeof(double) << endl << endl;


    system("pause");
    return 0;
}

f:id:ti-nspire:20181117131145p:plain