How to determine size of variable without size of operator?

Status
Not open for further replies.

dilip_devaraj

Newbie level 3
Joined
Feb 18, 2006
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,299
C

how to determine size of a variable without using sizeof operator
 

C

I think in C++ we can use calass and its easy to use.
is it tru?
 

Re: C

Interesting question.

I would write the following code to find the size of an integer in bytes (assuming no sizeof command and byte = 8 bits):

Code:
int i = 1;
int count = 1;
while (i <<= 8)
{
    count++;
}
//count should contain the size of the integer i in bytes.
//don't try to do this with doubles.

In general, using the sizeof operator is a much better idea.

-jonathan
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…