I have a section of code in which two array are declared with sizes of 6 and 13, but when 'sizeof()' is used the lengths are returned as 12 and 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)" << sizeof(races) << endl;
cout << "sizeof(classes)" << sizeof(classes) << endl;
system("pause");
return(0);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…