views:

80

answers:

1

I am trying to create a simple integer variable and can't get it to accept a value.
Why does the NSLog print out i=(null)?

int i;
i = 0;
NSLog(@"i=%@", i);

How do I create a simple index for an array?....

Thank you...

+9  A: 

You are creating the integer just fine, the problem is you cannot output it like that. %@ is used to output objective c objects, not simple c types.

try:

int i;
i=0;
NSLog(@"i=%d",i);
Alex Deem
That makes sense, but the same thing happens when I try use NSUInteger. Also the program crashes when I do any operation on the value of i, such as i++....
Michael
Maybe post the code that crashes... as you've described it, I don't understand why it wouldn't work.
Alex Deem
@Michael: `NSInteger` is a typedef to either `long` or `int`, depending on the platform. It's not an object. The corresponding object is a `NSNumber`. `i++` shouldn't be a problem. It crashes in `NSLog`. Without `i++` you try to print the object at address `0x0` which is equal to `nil`. This is valid. But with `i++` you try to access the object at address `0x1` which is protected memory and therefore it crashes when you access it.
Georg
Thank you gs... That cleared it up.
Michael