我有一段代码,其中声明了两个数组,大小分别为 6 和 13,但是当使用“sizeof()”时,长度返回为 12 和 26。
#include <iostream>
using namespace std;
int main(){
enum charRaces {DWARF,ELF,GNOME,HALFELF,HALFLING,HUMAN};
enum classes{WARRIOR,FIGHTER,RANGER,PALADIN,WIZARD,MAGE,ILLUSIONIST,PRIEST,CLERIC,DRUID,ROGUE,THEIF,BARD};
short int races[6] = {DWARF,ELF,GNOME,HALFELF,HALFLING,HUMAN};
short int classes[13] = {WARRIOR,FIGHTER,RANGER,PALADIN,WIZARD,MAGE,ILLUSIONIST,PRIEST,CLERIC,DRUID,ROGUE,THEIF,BARD};
cout << "sizeof(races)\t" << sizeof(races) << endl;
cout << "sizeof(classes)\t" << sizeof(classes) << endl;
system("pause");
return(0);
}