pointer question

Hi,I have a question related to pointer topic.I have a class omega as given below and 2 objects of this class ,in main I print their adresses,I expect the difference between them as much as sizeof an omega object(which I think is 30+4=34)
When I run the program,I see these adresses for om1 and om2 :

0X23ff10
0X23fee0
sizeof omega: 36


Is there something wrong here? OR I misunderstood what I studied.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class omega
{
private:
        char name[30];
        unsigned long number;
public:
        omega(char* nm,unsigned long num):number(num)
        {
        strcpy(name,nm);    
        }            
};

int main()
{
omega om("learning",12345),om2("pointers",12456);
omega *omptr,*omptr2;
omptr=&om;
omptr2=&om2;

cout<<"adress of om:\t"<<&om<<endl<<"value of omptr:\t"<<omptr<<endl<<endl;
cout<<"adress of om2:\t"<<&om2<<endl<<"value of omptr2:\t"<<omptr2<<endl<<endl;
cout<<"size of omega: "<<sizeof(omega);
}
Last edited on
Objects are not guaranteed to be in contiguous memory. Take a look at this to get you started:

http://en.wikipedia.org/wiki/Data_structure_alignment
So ,since it uses "word" it may not put my objects in memory just one after another.It's ok.
BUT,what about sizeof(omega)?It gives "36" as output for size of omega.I expected it to be 34.Do I miss something?
Thanks
Topic archived. No new replies allowed.