IOS development-OC language (I) oc data type,-ococ

Source: Internet
Author: User

IOS development-OC language (I) oc data type,-ococ

Share a set of materials learned during iOS development, and the next set is continuously updated:

OcData Type

Data Type: basic data type, pointer Data Type

Basic data types: numeric, numeric (char), Boolean, and void)

Pointer data type: class, id

Numeric: int, float, and double

CAndOcBasic Data Type

Int: Declares integer variables.

Double: declare double-precision Variables

Float: Declares floating point variables.

Char: declare a struct variable

Id: Generic pointer type

Enum: Declares the enumeration type.

Long: declares a long integer variable or function.

Short: declare short integer variables or functions

Signed: declares a variable of the signed type.

Struct: declare struct Variables

Union: Declares the data type of the shared object (union ).

Unsigned: Declares unsigned type variables.

Void: declares that a function has no return value or no parameter.

Description of Data Type formatting

Data Type oc keyword format description Guide

Integer int % d. % I

Short int % hd. % hi

Long int % ld. % li

Unsigned short integer int % u

Unsigned short % hu

Unsigned long % lu

Float % f

Double % f

Long double % lf

Character char % c

Specific data types

Integer type

The integer type in oc is represented by int, And the formatting symbol is represented by % I or % d.

For example, int a = 100;

The int type constant of the oc language defaults to the int type. After declaring a long type constant, you can add "l" or "L", for example:

Int B = 600; // long c = 888888888L;

Value range of storage space occupied by types

Byte 1 Byte-128-127

Short 2 bytes-2 '15-2' 15-1

Int 4 bytes-2' 31-2 '31-1

Long 8 bytes-2' 63-2 '63-1

Note: 2's 63 is the power of 2's 63

Floating Point Type

Floating-point variables can store decimal values.

There are two floating point types in oc

· Float valid numbers are 6-7 characters, and % f is used for formatting instructions.

· The valid double number is 15-16 characters. The format symbol is expressed as % f. % e or % g.

In oc, float constants are double by default. If you want to declare a constant as float, add f or F after the number.

For example, double m = 3.14159; // The correct float f = 3.14f;

Value range of storage space occupied by types

Float 4 bytes-3.403E38

Double 8 bytes-1.798E308-1.798E

StringChar

Char-type data is used to represent "characters" in the general sense, and % c is used to format the specifiers.

The character constant is a single character enclosed in single quotes,

Example: char achar = 'a'; char B = '0'; char cChar = 'ping'; value range:-128-127

"\ N", oc compiler treats this as a single character

Unsigned char value range: 0 ~ 255

The oc characters are encoded in Unicode and each character occupies two bytes. Therefore, they can be expressed in hexadecimal format,

For example, char c1 = '\ u0061 ';

Note: Unicode is globally unified.

Logical typeBoolean (Boolean)

The Boolean type refers to the variables used to store the true and false values. It is generally used for program flow control.

Values of the Boolean type can be true or false, or 0 or a non-0 integer can be used to replace true and false, which is different from the java language.

Instance:

Boolean flag = true

If (flag)

{

NSLog (@ "hello iphone ");

}

Qualifier

· Long int: declares an integer variable whose variable XX is long. The format symbol is ¥ % li, for example: long int;

· Long int: declares an integer variable whose variable XX is long, in the format of % lli, for example: long int B;

· Long double: basically the same as int;

· Unsigned int: Declares unsigned integer variables, for example, unsigned int c;

· Signed int: Declares signed integer variables. For example, signed int d.

VoidType (null type)

Tells the compiler that there is no value of any range type

Variables cannot be declared like other data types

Example: void I = 10; // Error

Void is usually used together with the method, for example:

-(Void) test

{

// Code

}

IdType

Id is a unique data type in oc. It can store any type of objects. In a sense, it is a general object type.

· Declare number as an id variable,

For example, id number;

· Format description: % p

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.