Video Tutorial: Objective-C Data Types: Integer

The first video in our Objective-C data types series. Learn how integers work in Objective-C, on both 32-bit and 64-bit platforms.

Challenge

Your challenge is to add this code to your project, fill in the question marks, and answer the question:

// Fill in the question marks
uint32_t u32 = 4;
int16_t i16 = 5;
NSInteger nsInt = 6;

NSLog(@"uint32_t: %??? (%lu bytes): %??? to %???", u32, sizeof(u32), (int)???, (int)???);
NSLog(@"int16_t: %??? (%lu bytes): %??? to %???", i16, sizeof(i16), (short)???, (short)???);
NSLog(@"NSInteger: %??? (%lu bytes)", ???, sizeof(nsInt));

// Why is this incorrect on 64-bit architecture?
nsInt = 1000000000000000000;
int myInt = (int)nsInt;
NSLog(@"NSInteger: %ld", (long) nsInt);
NSLog(@"myInt: %d", myInt);

Download solution

Helpful links

Add a rating for this content

Contributors

Comments