Jul 30, 2006 #1 D 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
Jul 30, 2006 #2 amiralib Member level 4 Joined Mar 6, 2006 Messages 77 Helped 17 Reputation 34 Reaction score 7 Trophy points 1,288 Location Ian - Tabriz Activity points 1,678 C I think in C++ we can use calass and its easy to use. is it tru?
Aug 1, 2006 #3 J jonw0224 Full Member level 4 Joined Nov 22, 2004 Messages 211 Helped 45 Reputation 90 Reaction score 14 Trophy points 1,298 Location USA Activity points 2,528 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
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