The sizeof Operator
Although you should never make assumptions about the size of a data type in your program, sometimes you need to know this information. This might be when performing dynamic memory allocation using library routines such as malloc, or when writing or archiving data to a file. Objective-C provides an operator called sizeof that you can use to determine the size of a data type or object. The sizeof operator returns the size of the specified item in bytes. The argument to the sizeof operator can be a variable, an array name, the name of a basic data type, an object, the name of a derived data type, or an expression. For example, writing
sizeof (int)
gives the number of bytes needed to store an integer. On my MacBook Air, this produces ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access