"JKop" <NULL@NULL.NULL> wrote in message
news:lxKjc.5873$qP2.14002@news.indigo.ie...[color=blue]
> Naren posted:
>[/color]
[snip][color=blue]
> Please read this using a monospace font if possible.
>
>
> class Hello
> {
> public:
>
> int j; //Let's say int is 32-bit = 4 bytes
> double p; //Let's say double is 64-Bit = 8 bytes[/color]
[color=blue]
> char t; //Let's say char is 8-bit = 1 byte[/color]
I suppose you don't mean to say 1 byte is 8 bits.
C++ standard ensures that a byte is _at least_ 8 bits, could be more.
[color=blue]
> Hello(void)
> {
> j = 5;
> p = 43.4;
> t = 's';
> }
>
> double GiveMeSecretNumber(void)
> {
> return j + p;
> }
>
> };[/color]
In C++ you don't need to type void if a function takes no parameters.
Look at thos FAQ -
http://www.parashift.com/c++-faq-lit....html#faq-29.4
[snip][color=blue][color=green]
>>[/color]
> What you've done is declared a variable, very simply. Just as how I've
> declared "int numbr". Our variable is of type "Hello" and it's name is
> "greeting". When a variable's type is a class, we call it an object! The
> first thing that happens is that memory is allocated for the member
> variables, ie. j p t, totalling 13 bytes.[/color]
How can it be 13 bytes always? Can't there be padding between the fields?
I could very well expect sizeof(Hello) to be 24 bytes.
-Sharad