finding the size of a data structure in bytes?

R

Ragemare

I need to find the size of a class or struct in bytes, I did know how to do
it but I forgot and I can't find anything that tells me (I had a book with
it in but I lost it). You would think this kind of thing would be pretty
easy to find information on.
 
P

Petec

Ragemare said:
I need to find the size of a class or struct in bytes, I did know how
to do it but I forgot and I can't find anything that tells me (I had
a book with it in but I lost it). You would think this kind of thing
would be pretty easy to find information on.

The sizeof operator:
sizeof yourclassorstructhere

It gives the size of your class or struct in units of the size of char.
(Which is usually a byte.)

- Pete
 
K

Kevin Goodsell

Petec said:
The sizeof operator:
sizeof yourclassorstructhere

It gives the size of your class or struct in units of the size of char.
(Which is usually a byte.)

Which is /by definition/ a byte. Always.

-Kevin
 
A

Artie Gold

Petec said:
The sizeof operator:
sizeof yourclassorstructhere

sizeof(some_type)

or

sizeof an_instance_of_some_type
[Using parenthesis in this second case wouldn't be incorrect, but would
obfuscate its purpose.]

HTH,
--ag
 
M

Muhammad Naveed Yaseen

Kevin Goodsell said:
Which is /by definition/ a byte. Always.

-Kevin

Just to add up clarity, the bitwise size of this c++ byte may be more
than 8 bits. This is different than more widely perceived term "byte"
in context of marketing materials for specific platforms, where it is
understood to be 8 bit in size. In c++, byte is defined as unit of
addressability.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top