Memory of a class

This is a silly question, but I'm genuinely curious and I'm not sure how I would test it.

I know an integer takes 4 bytes. But how much more space is an object that holds nothing but an integer

1
2
3
4
class Number {
public: 
   int myNumber;
}


1
2
3
4
5
int main() {
   Number someNum;
   someNum.myNumber = 232; // arbitrary value
   return 0;
}
Last edited on
Use sizeof
1
2
3
4
5
6
7
8
class Number {
   int myNumber;
};

int main() {
   std::cout << sizeof(Number) << std::endl;
   return 0;
}
Last edited on
Give a man a fish and he will eat for that day. Teach a man how to fish and.... you get what I mean....Thanks so much!
Topic archived. No new replies allowed.