yeesterbunny
yeesterbunny

Reputation: 1847

Typecast char as NSInteger

I googled a bit on this topic but I couldn't really find anything helpful. Here's the code that I'm confused about:

const char *beginning = "Love";
NSLog(@"%s", beginning); //Love
NSLog(@"%d", (NSInteger)beginning); //14687

What does (NSInteger)beginning mean? Why does it output 14687?

Thanks.

Upvotes: 0

Views: 771

Answers (1)

deleted_user
deleted_user

Reputation: 3805

You are not casting a char to NSInteger, you are casting a pointer to a character array to an NSInteger. The value is the value of the pointer to that character array.

See this link for tutorials on pointers and arrays in C

http://pw1.netcom.com/~tjensen/ptr/pointers.htm

Upvotes: 3

Related Questions