iOS summary static variable static, global variable extern, local variable, instance variable

Source: Internet
Author: User
Tags variable scope

1. Static variable statics

What is a static variable: triggered from an object-oriented angle, when a data object is required to serve an entire class rather than an object, and there is a need to not break the encapsulation of the class, it requires that the member be hidden inside the class, and when there is a requirement to be invisible, static can be used. The advantages of static variables: 1, save memory.    Static variables are stored only one place, but are used by all objects.    2, its value can be updated. 3, can improve time efficiency. Whenever an object updates a static variable once, all objects have access to the updated value.
2. Global variables extern What is a global variable: Also known as an external variable, is a variable defined outside the method. It does not belong to which method, but belongs to the entire source program. The scope is the entire source program. If the global convenience and local variables have the same name, then in the local variable scope, the global variable is masked and does not work. Try not to use global variables when programming. 3, local variables what is a local variable: is defined within the method of the description. Its scope is limited to the method within. 4, instance variables are defined in the class instance variables, can be used within each method. 5, the const variable value is immutable 6, volatile indicates that the variable can be changed at any time from: http://www.devdiv.com/ios_static_extern_-blog-319669-51270.html

iOS summary static variable static, global variable extern, local variable, instance variable

Related Article

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.