Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 556875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:57:58+00:00 2026-05-13T11:57:58+00:00

I had a question regarding the use of asterisks in Objective-C. Just to be

  • 0

I had a question regarding the use of asterisks in Objective-C. Just to be clear: I understand what pointers are and everything in procedural C. I was wondering two things though:

1) Why are all (references to) Objective-C objects pointers? Why not plain variables? (i.e. NSArray array = [[NSArray alloc] init];)

2) Why do you omit the asterisk when calling method?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:57:59+00:00Added an answer on May 13, 2026 at 11:57 am

    1) Why are all (references to)
    Objective-C objects pointers? Why not
    plain variables? (i.e. NSArray array =
    [[NSArray alloc] init];)

    Think of an Objective-C object as a glorified struct for a moment.

    NSArray array; in a local scope would be an object “allocated” on the stack. NSArray *array; indicates an object backed by a hunk of memory, typically allocated from the heap.

    Long, long, ago it was decided that Objective-C wouldn’t support objects on the stack. Mostly, because doing so would make memory management a gigantic mess (mainly, -retain of something on the stack doesn’t make any sense at all).

    Since Objective-C was designed as a pure superset of C and, unlike C++, doesn’t try to modify the basic behavior of C, having the * in there seemed natural.

    Note that id breaks this, but id is also a completely generic type. And it is, in fact, possible to have Objective-C objects on the stack. In Snow Leopard, Blocks are actually Objective-C objects and they do start on the stack. It isn’t, however, supported for you to create your own objects on the stack.

    2) Why do you omit the asterisk when
    calling method?

    Because you aren’t dereferencing the pointer to the object and that pointer to the object is critical within the method implementation itself. When you say…

    [anArray objectAtIndex: 5];
    

    … it is exactly equivalent to writing …

    objc_msgSend(anArray, @selector(objectAtIndex:), 5);
    

    … and when you implement said method ….

    - (id) objectAtIndex: (NSUInteger) anIndex;
    

    … it is exactly equivalent to implementing this C function …

    id object_at_index(id self, SEL _cmd, NSUInteger anIndex) { ... }
    

    That is, an Objective-C method is really just a C function that takes two or more arguments. As a matter of fact, you can paste this line of code into any method implementation and it’ll “just work”:

    NSLog(@"method %@", NSStringFromSelector(_cmd));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a question regarding this matter some days ago, but I'm still wondering
I've just had a nagging question for a while regarding iPhone app user interfaces.
Note: This question was spawned from another question I had regarding the use of
I have a follow-up question regarding an issue I previously had on SO here
I had a question regarding generating a specific computer ID for licensing purposes. Preferably
I had a quick question regarding the datacontractserializer. Maybe it's more of a stream
I had a quick question regarding RegEx... I have a string that looks something
I have a question regarding the MVVM design for C#/WPF. I've had a look
I had a question regarding the split function used in Visual Basic. As of
I have one question regarding unwanted extra jar files . First I had planned

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.