B
ben
Hi guyz,
I have a small doubt in the following program.Upon
execution,the program shows that size of structure variable is 20
whereas size of its individual elements is 4,4,4,1 and 4.If we add the
size of individual elements we get the total as 17.Then how come the
size of the structure varialble is 20?(The program gives the same ans.
on linux as well as WINDOWS(VC++)).
#include<iostream>
using namespace std;
struct Column
{
char *fieldName;
int fieldType;
void *defaultValue;
void *value;
bool nullFlag;
};
int main()
{
Column a;
a.nullFlag=false;
cout<<sizeof(a)<<endl;
cout<<sizeof(a.fieldName)<<endl;
cout<<sizeof(a.fieldType)<<endl;
cout<<sizeof(a.defaultValue)<<endl;
cout<<sizeof(a.nullFlag)<<endl;
cout<<sizeof(a.value)<<endl;
return 0;
}
Program output:20
4
4
4
1
4
bye,
ben
I have a small doubt in the following program.Upon
execution,the program shows that size of structure variable is 20
whereas size of its individual elements is 4,4,4,1 and 4.If we add the
size of individual elements we get the total as 17.Then how come the
size of the structure varialble is 20?(The program gives the same ans.
on linux as well as WINDOWS(VC++)).
#include<iostream>
using namespace std;
struct Column
{
char *fieldName;
int fieldType;
void *defaultValue;
void *value;
bool nullFlag;
};
int main()
{
Column a;
a.nullFlag=false;
cout<<sizeof(a)<<endl;
cout<<sizeof(a.fieldName)<<endl;
cout<<sizeof(a.fieldType)<<endl;
cout<<sizeof(a.defaultValue)<<endl;
cout<<sizeof(a.nullFlag)<<endl;
cout<<sizeof(a.value)<<endl;
return 0;
}
Program output:20
4
4
4
1
4
bye,
ben