Zhang OC Basics Review 02_ member variables (attributes), local variables, global variable differences

Source: Internet
Author: User

member variables :

Variables written in curly braces of class declarations, which we call member variables (attributes, instance variables)

Member variables can only be accessed through objects

Note: Member variables cannot leave a class and are not member variables after leaving the class

Member variables cannot be initialized at the same time as defined

Storage: Heap (in the storage space of the heap that corresponds to the current object)

Data stored in the heap is not automatically freed and can only be manually released by the programmer

@interface person:nsobject{    int  _age;     *_name;} @end    

Global variables:

Variables that are written outside the function and curly braces, which we call global variables

Scope: Starts from the defined line and continues to the end of the file

A local variable can be initialized at the same time as the initialization, or it can be defined.

Storage: Static Zone

When the program starts, it allocates storage space until the end of the program is released.

int A; int ten;

Local variables:

Variables written in functions or blocks of code, which we call local variables

Scope: Starts with the defined line, until it encounters curly braces or return

Local variables can be initialized or defined at the same time.

Storage: Stacks

The data stored in the stack has a feature that the system will automatically release to us

int Main (intconstChar * argv[]) {    //  like this is written in {}, or in a function , {} ended or the function died of    intten;    {        int  value;    }     return 0 ;}

Zhang OC Basics Review 02_ member variables (attributes), local variables, global variable differences

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.