Little fat says things.------Extern,static and const differences and how to use in iOS

Source: Internet
Author: User

In Layman's words:

when the extern field is used, the declared variable is a global variable and can be called, as well as a narrower term: extern is able to extend a variable in a class to a class;

Static variables are statically declared, and when the value of the variable is changed, the change is saved and the value is read once each time it is used.

Const declares that the value of a variable is immutable. is a property of ReadOnly and cannot change the value of a variable.

Detailed use Method:

How to use 1.static: static nsstring *str = @ "haha";

How to use 2.const: nsstring *const str = @ "haha";

How to use 3.extern: Declare a variable extern nsstring *str = @ "123" inside A.h; This declares a global variable. In B.h inside the same write code extern nsstring *str, and then b.m inside directly print STR will be able to print out 123来, the use of the time does not need to import A.h file header, or whether the classification has been created and so on.

Hope to have some help, later when writing code can be more tall on some, is also a skill.

Chubby say things------iOS extern,static and const differences and how to use

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: 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.