Sizeof vs Strlen

sizeof and strlen() do different things. In this case, your declaration char string[] = “october”; is the same as char string[8] = “october”; so the compiler can tell that the size of string is 8. It does this at compilation time. However, strlen() counts the number of characters in the string at run time. So, … Read more

Sizeof arrays and pointers

“…after all it’s just a pointer…”? No. Array is not a pointer. Array is an array object: a solid continuous block of memory that stores the array elements, no pointers of any kind involved. In your case array has 6 elements of size 4 each. That is why your sizeof evaluates to 24. The common … Read more

sizeof Java object [duplicate]

The question is not meaningful, at least not without further context. The notion of “size” in Java is only reasonably well defined for primitives: A byte is 8 bit (unsurprisingly) an int is 32 bit, a long 64bit, etc. (see e.g. http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html for a full list). For object instances, it’s more complicated, because: Object instances … Read more