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 7651213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:27:00+00:00 2026-05-31T11:27:00+00:00

int helloness; @interface test : NSObject @end vs @interface test : NSObject{ int helloness;

  • 0
int helloness;
@interface test : NSObject
@end

vs

 @interface test : NSObject{
int helloness;
}
@end

Do I understand that following are true and the only meaningful differences between the above two blocks:

  • in both blocks, the implementation of test.m can use helloness variable internally, like an ivar
  • in the first block, helloness will exist for any class that imports this .h but is otherwise private only to test.m in the second block

In the first block, is this technically what is considered a “global variable” in that any class that imports this will have access to the same contents of helloness?

What happens if multiple header files have a declaration for helloness and you import them all?

Similar to this, consider this implementation:

 @implementation AClass

 int food=5;

Here, food acts like an internal iVar, even though it was not declared in any @interface ?

  • 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-31T11:27:01+00:00Added an answer on May 31, 2026 at 11:27 am

    In your first example, helloness is a global variable. It can be seen by any file which imports that header. If you include multiple headers which also declare an int helloness variable, I believe you’ll get a warning from the compiler, and all of them will point at the same memory location. If you include another header which declares a helloness of type other than int, I believe you’ll get a compiler error.

    In the second example, helloness is an instance variable (ivar). Its value (memory location) is specific to each instance of AClass. (Anything can access it: e.g. AClass *instance = [[AClass alloc] init]; instance->helloness = 7; However, direct access to ivars is generally avoided in ObjC — we use accessors and/or properties instead.)

    In the third case, food is still a global variable, but its visibility is restricted to the implementation file it’s declared in. Any instance of AClass, as well as any other classes or categories or functions implemented in the same file, can reference food, and all those references are to the same memory location.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

int main(void) { std::string foo(foo); } My understanding is that the above code uses
int pcap_dispatch(pcap_t *p, int cnt, pcap_handler callback, u_char *user) I understand that pcap_dispatch calls
int i=5; f() { i++; i--; } For the above code if three threads
*(int *)CV = (int)0; I was looking at a C code and can't understand
int X = a-b; int d = Math.Abs(X); I am pretty sure that .NET
int n == 0; if (n == null) { Console.WriteLine(......); } Is it true
int item; cin >> item; That's in my code, but I want the user
int main() { char myString = NULL; realloc(&myString, 5); strncpy((char *)&myString, test, 5); }
int x = fromString(test) : could not deduce template argument for 'ValueType' int x
int main() { std::vector<int> v; v.push_back(1); v.push_back(3); v.push_back(2); std::for_each(v.begin(), v.end(), std::cout << boost::lambda::_1 <<

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.