This question already has an answer here:
- Zero size struct 3 answers
In C++, Empty class size always 1
. But If I write zero size array in class like this:
#include<iostream>
using namespace std;
class A
{
private:
int arr[0]; // zero size array
};
int main()
{
A obj;
cout<<"Size of a class :"<<sizeof(obj)<<" byte"<<endl;
return 0;
}
Output:
0
So, Why output 0
? Is it compiler bug?
Note: I have used g++ (version - 5.4.0)
compiler.
Aucun commentaire:
Enregistrer un commentaire