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 ...
Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.