C-Language Basics-data types

Source: Internet
Author: User

Data type

The following is just a personal study note, because I am also just contact, so there may be errors, if there are errors, please point out

1. Programming Specifications

Code indentation: Uniformly indented 4 characters, cannot use a Space, Tab tab stop

constants, variable naming: Constant naming uniform uppercase format, member variables starting with m_, ordinary variables with the actual meaning of the name associated with the first letter of the type, and the first letter of the name is required to uppercase, the pointer to its identifier preceded by the P character, and the name of the first letter uppercase

Function naming: Function naming requires first letter capitalization, followed by letter case

Note: A comment code is required, and if the comment is on a line with the code, the comment should be to the right of the code, and if multiple lines of comments appear consecutively and the comment is shorter, the comment should be aligned

2. Identifiers

Identifiers: Names of variables, constants, functions, arrays, etc. are identifiers

Naming rules for identifiers:

(1). Must be preceded by a letter or underscore, you cannot start with a number or a symbol

(2). In addition to the beginning, other positions may consist of letters, underscores, or numbers, but cannot be symbols

(3). Case-sensitive, uppercase and lowercase letters of the English alphabet represent different meanings

(4). Cannot be named with the keyword, such as int int; because int is a keyword, you can name int int;

(5). Naming is best related to meaning, such as the width of a named rectangle, can be named width, height can be height

(6). The name can be any length, but at least the preceding eight bits have to be different, because some compilers may not recognize the eight-bit

3. Data type

Data type: base type, constructed type, pointer type, empty type

Base type: That is, the underlying type, including integer (short, Basic, long), character, float (real (single-precision floating-point, double-precision floating-point), enum-type

Constructed type: is the basic type of data, or uses the already constructed data type, adds, designs constructs the new type, consists of the basic type, including the array type, the struct type, the common body type pointer type: C language essence, the pointer value represents the address of a memory

NULL type: The keyword is void, which functions in terms of the qualification of function returns and the qualification of function parameters, when a function does not return a value, you can use the return value type set by the null type

4. Constants

Constant: The value of the program's operation is unchanged.

Constants can be divided into: Numeric Constants (integer constants, floating-point constants (real constants)), character constants, symbolic constants

(1). Integral type constant

Integer constant: Is the direct use of integral type constants, can be long integer, short integer, symbolic Integer, unsigned integral type

16-bit integer constant: Unsigned range of values: 0-2xy16-1 symbol range:-(2xy16+1)/2-+ (2xy16-1)/2

32-bit integer constant: Unsigned range: 0-2xy32-1 value range:-(2xy32+1)/2-+ (2xy32-1)/2 Note: XY represents the second party, 2XY16 represents 2 of the 16 parties, 2XY32 represents 2 of the 32-time party

a=123l L represents the Long shape a=123u u for unsigned integer a=0123 precede the constant with a 0 for octal a=0x123 in front of the constant plus a 0x for hexadecimal a=1.23f F for single precision a=1.23 if not written, the default Consider the double-precision type

Decimal integer decimal integer is the binary way the numeric value stored in the computer's memory is expressed in the form of a complement, the complement of a positive number is the same as the original code, and the complement of negative numbers is the binary form of the absolute value of the values of the bitwise negation plus 1

For example, the decimal 11 in memory is represented as 10,110 binary-11 in memory should be in the form of a first-take counter-1111111111110100 and then add 1 operations, the final expression is 1111111111110 101

(2). Floating-point constants (integer constants)

Floating-point constants: With integral and fractional parts, separated by a decimal point

The means of expression are: scientific counting method, exponential way

Scientific counting methods are described in decimal notation, such as a=1.23

Exponential mode is displayed exponentially, such as 23e2 means that 2300,23e-2 indicates that 0.32,e can be uppercase or lowercase

(3). Character-type constants

Character constants: Unlike constants, delimiter-restricted delimiters are "," "character constants are divided into character constants and string constants

Character constant: Similar to ' a ', ' n ', with only one character in it, case-sensitive

String constants: Similar to "abcdef", which can have more than one character or 0 characters, the system automatically in the back of the 0\ represents the end

Note: Because the string is followed by a 0\ end flag, the length should be added 1

(4). Escape character

Escape character: Escape character is not output, such as \ n, not output but converted to newline

The escape character is: \ n: Carriage return newline \ t: horizontal Skip to next tab position \v: Vertical jump grid \b: Backspace \ r: Return to \f: Go paper to page \ \: backslash ' \ ' \ ': single-quote character \a: the characters represented by the ringing \ddd:1-3 bit octal number \x Hh:1-2 the character represented by the hexadecimal number

(5). Symbolic constants

Define a symbolic constant, easy to modify and read, such as the requirement to find the area of the circle, you can define a single constant Pai, where Pai is a symbolic constant, #define PAI 3.14;

4. Variables

Variable: The amount of change that can be changed in the program run,

Variables can be divided into: integer variable, floating-point (real) variable, character-type variable

(1). Integer variable

Integer variable: is a variable stored with an integer value

Integer variables can be divided into: Signed basic integer, unsigned basic integer, signed short integer, unsigned basic short integer, signed long shape, unsigned long shaping

Signed basic integer: The keyword is signed int, the keyword signet can be omitted, occupies 4 bytes in memory, the value range is 2147483648-2147483647 define a signed basic shaping, example int A; A=10;signet can omit

Unsigned basic integer: The keyword is unsigned int, the keyword int can be omitted, occupies 4 bytes in memory, the value range is 0-4294967295 to define an unsigned basic integer, example unsigned A; A=10;int can omit

Signed short integer: The keyword is a signet short int, the keyword signet and int can be omitted, which accounts for 2 bytes in memory, the range is 32768-32768 to define a signed shorter integer, for example, a=10 signet and int can be omitted

Unsigned short integer: The keyword is a unsigned short int, the keyword int can be omitted, occupies 2 bytes in memory, the value range is 0-65536 to define an unsigned shorter integer, an example of a a=10;int can be omitted

Signed long shaping: The keyword is signet long int, the keyword signet and int can be omitted, within the presence of 4 bytes, the range is 2147483648-2147483647 defines a signed long shape, example long A; a=10; Signet and int can be omitted

unsigned long shaping: The keyword is unsigned long int, the keyword int can be omitted, occupies 4 bytes in memory, the value range is 0-4294967295 to define an unsigned long shape, example unsigned long A; a=10; int can omit

(2). Floating-point (real) variable

Floating-point (real) variable: A variable that stores a real integer, consisting of an integer and a fractional part

Floating-point (real) variables can be divided into: single-precision type, double-precision type, long double-precision type

Single precision type: The keyword is float, which occupies 4 bytes in memory, the range is -3.4*10xy38-3.4*10xy38 defines a single precision type, example float A; a=1.23;

Double type: The keyword is a double, which accounts for 8 bytes in memory, and the range -1.7*10xy308-1.7*10xy308 defines a double type, for example double A; a=1.23;

Long double type: The keyword is a long double, which accounts for 8 bytes in memory, the range is -1.7*10xy308-1.7*10xy308 defines a double type, example long double A; a=1.23;

(3). Character type variable

Character constants: variables that store character constants

Char variable: keyword chars, 1 bytes in memory, value range-128-127 defines a character variable, example char A; a= ' C ';

5. Storage categories for variables

The storage class of variables can be divided into static storage and dynamic storage from the generation time.

Static storage: Refers to the fixed storage mode of the program operation allocation.

Dynamic storage: Dynamically allocating storage space as needed during program operation

Modifiers are auto (auto), Static, register (register), external (extern)

(1). Auto variable

Auto is the modification of a local variable to be automatic, and each time it executes to define the variable, it produces a new variable and re-initializes it.

(2). Static variable

The static variable is a statically variable, and during statement execution, the static variable will always hold his value, and the initialization operation only works at the first execution, and in subsequent runs, the variable holds the value of the last execution of the statement block.

(3). Register variable

Register variable is called Register storage class variable, you can put a local variable in the hardware register instead of memory, this can not occupy memory space, but the editor ignores register to modify the variable, sometimes can not get the address of the variable, and portability is poor, so rarely used

(4). extern variable

An extern variable, called an external storage variable, declares an external variable that will be used in the program but has not yet been defined, and can be linked to an external variable

6. Mixed operations

Mixed operations can be performed between different types, in which different types of data are converted to the same data first and then computed, which is usually a computer auto-conversion

C-Language Basics-data types

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.