OBJECTIVE-C Data types

Source: Internet
Author: User


Keyword keyword definition: words > Keywords that are given special meaning by C language: All lowercase > Keywords are displayed in the Developer tool Special colors * compiler is strictly case-sensitive *note: The keyword cannot be used as the definition of identifier such as variable name \ Function Name: Programmer in Program Naming rules for your own moniker 1> can only have 26 letters of case or 10 Arabic numerals 0-9\ underscore 2> strictly case-sensitive 3> cannot start with a number 4> not use keywords as identifiersUse of annotations1. The range of single-line annotations: Any place can write comments: Outside the function \ Inside, each statement after the scope of action:from the first slash to the end of this lineShortcut keys:Command +/2. The scope of the multi-line annotation function:from the first/* to the nearest one * /3. Precautions for use of annotations 1. Single-line comments can nest single-line comments multiline Comments 2 Multiline comments can be nested single-line comment 3. Multi-line annotations cannot nest multiple lines comment data type C language Data classification view common data types: int double float char * integer: For accurate, table-shaped integers, The following three types are divided according to the range of representations: short integer < integer (int) < long integer * (float type): Used to mark Decimals, according to the range and precision are divided into the following two kinds: * Single-precision Degrees floating point decimals (Folat) < double-precision floating-point (double) *note:float can only guarantee that 7-bit numbers are valid!!!!! * Character type: Used to describe a single character, Char constant: represents some fixed data, that is, data integer constants that cannot be changed
      • A decimal integer. such as 356,-120,0.
      • An octal integer. Constants in octal form start with 0, such as 0123, which is the decimal 83;-011, which is the decimal-9.
      • A hexadecimal integer. Hexadecimal constants start with 0x, such as 0x123, which is the decimal 291.
      • A binary integer. Every two in a 0b start

Practice Constants Note: Single-precision decimals: ends with F 0.0 and also implements constantsCharacter Constantscharacter constants are enclosed in ' (single quotation marks) and behave in two ways:1> General way a character is enclosed in ", note that there can be only one character .2> special forms are started with \, they are not displayed directly on the screen, but are displayed according to their specific functions, these constants are:

\n Newline,Equivalent to hitting enter.

\ t Skip to the next tab position, which is equivalent to pressing the tab key on the keyboard. \ b Backspace is equivalent to clicking backspace.
\ r Enter.
\ f Form feed, the cursor moves to the beginning of the next page.
\\ Output \ character, that is, a \ character is displayed on the screen.
\ ‘Output’ character, which means to display a 'character' on the screen.
\ "Output" character, that is, a "character" is displayed on the screen.
\ ddd Characters represented by 1 to 3 octal numbers.

For example, using ' \376 ', a black block is displayed on the screen. \XHH a 1-bit to 2-bit hexadecimal number representation of the character. Note that x cannot be lost. A string constant string constant is different from a character constant, where the string constant is surrounded by a string, and the system automatically adds a string end flag ('% ') at the end of the string constant. Custom Constants

    • Format: const data type constant NAME = value
      • Example: const int NUM = 998
The basic concept of a variable represents data that can be modified frequently. When the value of a data needs to change or be uncertain, it should be represented by a variable. The variable name of the format data type that defines the variable;
    • Define variables (declarations) that must be defined before any variables are used.

    • Define the variables: Allocate a chunk of memory to the variable to store the data later.
    • If you define more than one variable, you allocate different storage space for each variable.
      Different types of variables occupy different sizes of storage space. Memory is extremely limited, allocating the appropriate storage space
    • Considerations for variable names
    • Specification of a named variable
    • Variable names are identifiers, so you must strictly abide by the naming principle of identifiers
    • Variable names should be as much as possible to understand the text, concise
Initialization and use of variables: int a = 10; Note: here equals =, not "equal" in mathematics, but the assignment operator in C, which assigns the right constant 10 to the left variable value
    • (2) Specifications: Habit will be = on each side plus a space

The first assignment of the initialization variable of the variable is initialized with two forms > first defined, followed by the initialization of int A; A = 12;> defines simultaneous initialization of int a = ten, B = 12; Full initialization of int A, b = 10; Partial initializationOther forms of batch initializationint A, b, c;a = b = 10; What is the data stored in the initialization?

1) Random number

2) The storage space allocated by the last program, some contents, "garbage"
3) Some data that the system is using


Modifying the value of a variable
    • You can modify the value of a variable and assign it multiple times. Each assignment will overwrite the original value
Use the printf function to output the value of the variable, corresponding to the placeholder int->%d or%i double-> the scope 1 of the%lfchar->%cfloat->%f variable.   The global variable starts at the end of the program by the line that defines the variable 2. Local variables start at the end of the code block from the defined line of the variable
    • Scope Supplemental Description (Understanding):
      • The variables defined in the main function can only be used in the main function, and cannot be used in other functions. Also, variables defined in other functions cannot be used in the main function. Because the main function is also a function, it is parallel to other functions.
      • Parameter variables are local variables that belong to the modulated function, and argument variables are local variables that belong to the keynote function.
      • Allows the use of the same variable names in different functions, which represent different objects, allocate different units, do not interfere with each other, and do not confuse. While it is permissible to use the same variable name in different functions, it is not advocated to use the same variable name in different functions in order to make the program intelligible.
Memory analysis memory for variables the storage space used by a variable in bytes is not only related to the variable type, but also to the compiler environment. The same type of variable, the storage space used in different compiler environment is not the same
    • The number of bytes consumed is related to the type, but also to the compiler environment
    • Memory from large to small addressing
    • The address of the first byte of a variable storage unit is the address of the variable
    • Any variable is stored in memory in the form of a binary binary. The binary form of a negative number is actually the binary form of its positive number and then +1. (The inverse means 0 change 1, 1 to 0)
Type 16-bit compilers 32-bit compilers 64-bit compilers
Char 1 1 1
Int 2 4 4
Float 4 4 4
Double 8 8 8
Short 2 2 2
Long 4 4 8
Long Long 8 8 8
void* 2 4 8
Value range If the value is assigned beyond the range of variables, then the loss of precision, the "garbage" ("junk data" means not the data we want
Key Words the number of bytes occupied Representation Range
Int 4 -2 (31) ~ 2 (31)-1
Signed Short int 2 -2 (15) ~ 2 (15)-1
Signed Long int 4 -2 (31) ~ 2 (31)-1
unsigned int 4 0 ~ 2 (32)-1
unsigned short int 2 0 ~ 2 (16)-1
unsigned long int 4 0 ~ 2 (32)-1
Float 4 Absolute E-37 ~ e+38
Double 8 Absolute E-307 ~ e+308
The printf function printf function is a standard library function that can output the results of a program operation in an exact format.
    • The printf function is called in the following format:
    • printf ("Format control string", output item list);
    • For example:printf("%d,%d",a, b);
    • Format characters (format characters are used to specify the data type and output format of the output item)

      • D format: Used to output decimal integers. There are several ways to use this:
      • %d %hd %ld
      • o Format: output integers in unsigned octal form
      • X format: output integers in unsigned hexadecimal form
      • U format: Output integer in unsigned decimal form
      • C Format: output one character
      • S format: Used to output a string. There are several uses of the SCANF function to introduce the SCANF function prototype contained in the standard input output header file "Stdio.h" for receiving keyboard input content.
        • Format: scanf ("Format control string", entry address list);
        • For example: scanf ("%d", &num);
Common errors with scanf functions1,scanf ("%d\n");2,Scarf ("%d", A, b); be sure to add & because scarf is the data that corresponds to the location of the address value areascant memory operating principleuser-entered data ————— > buffers ————————— > Take user-entered data from the cacheNOTE: * If you input multiple spaces, enter, tab will be ignored by the system * if you want to get the content is more than one integer, the middle entered a number of spaces, enter, tab will be ignored by the system * if you want to get the content is more than the real type, the middle entered a number of spaces, carriage return, tab is ignored by the system summary: In order to prevent the mixed input space caused by the error, you can add a common delimiter to solve the problem of using "\ n" 1.scanf operation principle
    • The system will put the user input into the input buffer
    • The scanf method assigns a value to the format from the input buffer, one by one, and does not modify the original data if the type is inconsistent
    • If the contents of the input buffer are not empty, scanf will always be fetched from the buffer without requiring re-entry
Call the GetChar () function to empty the buffer's characters


OBJECTIVE-C 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.