[Study Notes-Objective-C] Chapter 10 variables and Data Types in Objective-C Programming version 6th

Source: Internet
Author: User

[Study Notes-Objective-C] Chapter 10 variables and Data Types in Objective-C Programming version 6th
Part 1. instance variables and attributesThe current trend is to use (_) as the start character of the instance variable name. In the implementation part, explicitly declare that the instance variable is private
ThereforeNoIn the subclass, you can directly obtain the instance variable value by name. OnlyInherited access methodObtains the value of an instance variable. Not Required@synthesizeCommand to generate an access method, as long as it is declared in the attribute.Part 2. Global VariablesLowercase g is the first letter of the global variable:int gMoveNumber = 1;Is also an external variable. External variable: accessed by any other method or function to access and change the value: Add a keywordextern:extern int gMoveNumber;
AddexternIs the declaration of the variable, not the definition. The Declaration will not cause variable storage space allocation, but will be defined. If you use many methods to access global variables, perform the following operations at the beginning of the file:externIf there are only a few accesses, it is best to separate them within each method.externStatementPart 3. Static variablesDefined as a global variable, but not an external variable: Except for methods in a specific class, no other method needs to access this specific variable:static int gGlobalVar = 0;: Methods or functions after this statement can access the value of gGlobalVar, but not methods and functions in other files.Part 4. enumeration data typeEnumeration type: provides a method to match an integer with a symbolic name.
To change the value of this integer, you can only change it in the place where the enumeration is defined. Example:enum direction {up, down, left = 10, right};The addition of element sequence, integer + 1, and so on.Part 5. typedef statement

Typedef: change the data type name.

typedef int Counter;Counter j,n;
Added the readability of variable definitions and clearly showed the purpose of using these variables in the program. Part 6. Data Type Conversion

Calculation of different data types:

If one of the operations is long double, double, floatType, the result is also long double, double, floatType. If one of the operands is Bool, char, short int, bit field, or enumeration type, all are converted to int type. If one of the operations is long long int, long intType, and the other operand is converted long long int, long intType, the result is also long long int, long intType. Both operands are intType, the result is also intType.

 

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.