[Study note-OBJECTIVE-C] "OBJECTIVE-C Programming 6th Edition" chapter tenth variables and data types

Source: Internet
Author: User

Part 1. Instance variables and properties
    • The current trend is to use (_) as the starting character for the instance variable name.
    • Explicitly declaring an instance variable in the implementation section is private
      • Therefore, you cannot get the value of an instance variable directly in a subclass by its name.
      • The value of an instance variable can only be obtained through an inherited access method in a subclass.
    • You do not have @synthesize to use directives to generate access methods, as long as you declare them in attributes.
Part 2. Global Variables
    • The lowercase g is the first letter of the global variable: int gMoveNumber = 1; It is also an external variable.
    • External variable: A variable that accesses and changes a value by any other method or function
    • Access: Add keywords extern : extern int gMoveNumber;
      • Add extern a declaration to a variable, not a definition. The declaration does not cause variable storage space allocations, and the definition will.
      • If there are many ways to access a global variable, the file starts onceextern
      • Only a few visits, it is best to declare them separately within each method. extern
Part 3. Static variables
    • is defined as a global variable, but not an external variable: in addition to the methods in a particular class, there is no other way to access this particular variable: the static int gGlobalVar = 0; method or function behind this statement can access the value of Gglobalvar, and the methods and functions in other files do not work.
Part 4. Enumeration data Types
    • Enum type: Provides a way to match an integer value to a symbolic name.
      • If you need to change the value of this integer, it can only be changed where the enumeration is defined.
      • Example:enum direction {up, down, left = 10, right};
      • An increase in the sequence of elements, an integer value of +1, and so on.
Part 5. typedef statements

typedef: Changing the name of a data type

typedefint Counter;Counter j,n;
    • The readability of variable definitions is increased, and the purpose of these variables in the program is clearly seen.
Part 6. Data type Conversions

Different types of data type operations:

    • If one of the operands is long double , double float type, the result is also, long double double float type.
    • If one of the operands is Bool,char,short int, bit field or enum type, all are converted to int.
    • If one of the operands is long long int , type, and the long int other operand is converted to long long int , type long int , the result is also long long int , long int type.
    • Two operands are all int type, the result is also int type.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

[Study note-OBJECTIVE-C] "OBJECTIVE-C Programming 6th Edition" chapter tenth variables and data types

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.