objective c

Objective-C Data Types

« Previous Tutorial Next Tutorial »

Data types simply used for declaring variables or functions of different types, which tells some information to the compiler like how much space, range, etc. require for. Here are the Objective-C data types given:

The array types and the structure types are referred to as aggregate types.

Note - The type of a function simpply specifies the function's return value type.

Integer Types in Objective-C

Here, the following table lists the details on the standard integer types with its storage sizes and their value ranges:

Type Storage size Value range
int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
char 1 byte -128 to 127 or 0 to 255
signed char 1 byte -128 to 127
unsigned char 1 byte 0 to 255
unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295
long 4 bytes -2,147,483,648 to 2,147,483,647
unsigned long 4 bytes 0 to 4,294,967,295
short 2 bytes -32,768 to 32,767
unsigned short 2 bytes 0 to 65,535

How to Get the Exact Size of any Data Type ?

To get the exact size of any data type on a particular platform, simply use the sizeof operator. Here is an example:

#import <Foundation/Foundation.h>
int main()
   NSLog(@"Storage size of int: %d\n", sizeof(int));
   return 0;

When the above code is compile and execute the above program, it would produce the following result on Linux:

2013-06-03 13:18:37.932 demo[28001] Storage size of int: 4 

Floating-Point Types in Objective-C

Here, the given table lists the details on the standard floating-point types with storage sizes and their range values with their precision:

Type Storage size Value range Precision
float 4 byte 1.2E-38 to 3.4E+38 6 decimal places
double 8 byte 2.3E-308 to 1.7E+308 15 decimal places
long double 10 byte 3.4E-4932 to 1.1E+4932 19 decimal places

Note - The header file named float.h defines macros, allows you to use the above values and the other details about the binary representation of real numbers in your Objective-C programs.

The void Type in Objective-C

In Objective-C, the void type simply specifies that, no value is available. Here are the situations, for the void type:

« Previous Tutorial Next Tutorial »


Quick Links
Signup - Login - Give Online Test