The Dark Horse programmer--c Language Foundation--Data type

Source: Internet
Author: User

------- iOS Training look forward to communicating with you! ----------


The so-called type is the arrangement of the Data allocation storage unit, including the length of the storage unit and the form of the data, different types are assigned different lengths and stored forms, and the type of data that C allows to use such as:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/5B/26/wKiom1UADkzwG951AAHW15kIPj4913.jpg "title=" D833c895d143ad4bb36ff4a681025aafa40f0616.jpg "height=" 541 "width=" 712 "alt=" wkiom1uadkzwg951aahw15kipj4913.jpg "/ >

Here's a brief introduction to several types:

First, the basic data Type--integer (int)

(a), the system for each integer data allocated 4 bytes of storage space, the number of integers has the following types:

(1) Short int: The type is named SHOTR int or shorthand is shorter, the system allocates 2 bytes of storage space, the variable value -32768~32767, the output time format is declared as:%d or%i.

(2) long int: The type is named long int or abbreviated to long, the system allocates 4 bytes of storage space, the range of variable values is -2147483648~2147483647, and the output is declared as:%ld.

(3) Double long Integer (Long long int): The type name is long long int or shorthand is long long, the system allocates 8 bytes of storage space, the range of variable values is -922337203654775808~ 922337203654775807, the output time format is declared as:%lld.

(4) unsigned basic integer (unsigned int): The type is named unsigned int or shorthand int, the system allocates 4 bytes of storage space, the range of variable values is 0~4294967295, the output is declared as:%u.

(5) signed integer (signed int): The type is named signed int or shorthand int, the system allocates 4 bytes of storage space, and the output is declared as:%d.

Here's a place to pay attention: unsigned and signed, when defined, they only change your top bit, and do not modify the length of the data type, the difference is: Determine whether the highest bit will be the symbol bit.

(b), the definition of integer variables

You can define an integer variable with the following statement:

(1) int A, B; Define two variables A and b at the same time

(2) int a = 10; Assign the initial value to a while defining the variable A.

Note: int a, int b; this notation is wrong, and you cannot write two definition types in a single statement.

Second, the basic data type--float type (float)

(a), floating point type can be divided into the following two types of floating-point numbers

(1) Single-precision floating point number (float): The system allocates 4 bytes of storage space, a total of 32 binary numbers, the range of variables is 3.4x10-38e~3.4x10+38e, the output is declared as:%f.

(2) Double precision floating point number (double): The system allocates 8 bytes of storage space, a total of 64 binary digits, the range of variables is 1.7x10-308e~1.7x10+308e, the output is declared as:%f.

(b), floating-point variable definition

You can define floating-point variables with the following statements:

(1) float A, F;

(2) Double b;

Three, the basic data type--character type (char)

(a), most systems currently use the ASCII character set, the basic set of the various character sets include 127 characters, including:

(1) Letter: Uppercase and lowercase 20 English letters

(2) Number: 0~9

(3) 29 Special symbols:! ' # & ' () * +,-.  /:; < = >?  [  \  ]  ^  _  {  | }  ~

(4) Whitespace: spaces, horizontal tabs (tab), vertical tabs, line breaks, page breaks

(5) Characters that cannot be displayed: empty (null) character (' \a '), warning (' s '), backspace (' \b '), carriage return (' \ R '), and so on.

The system allocates 1 bytes of storage space for the character variable, the value range of the symbol character type is -128~127, and the unsigned character number to the value range is 0~255.

(b), the expression of the character constant

(1) The characters represented by the symbol can be directly enclosed in single quotation marks, eg: ' A ', ' 9 ', ' Z ', also can be represented by the ASCII code value of the character, such as the decimal number 85 means the capital letter ' U ', hexadecimal number 0x5d '] ', octal number 0102 is the capital letter ' B ';

(2) A control that cannot be represented by a symbol can only be represented by an ASCII value, such as a decimal number of 10 for a newline, a six-digit 0x0d for a carriage return, and an octal number of 033 for ESC.

(c), character type definition

char A; means defining a character variable

A = ' B '; indicates that the character variable is assigned a value b

Iv. pointer Type (*)

Pointers are a special type of data that are not normally in other languages. The pointer is the address of the variable, and essentially the pointer is the address of the storage unit. Depending on the type of variable being referred to, it can be an integer pointer (int *), a floating-point pointer (float *), a character pointer (char *), a struct pointer (struct *), and a union pointer (union *), because the pointer involves a broad knowledge and a cluttered knowledge, which will be followed by the blog post , and then a more detailed introduction.

V. Types of construction

There are also four types in the constructed type:

(1) Array: An array is a set of ordered data, the array of data in the arrangement of a certain regularity, the index of the array is represented by the data in the array of the ordinal; at the same time, with an array name and subscript can uniquely confirm the elements in the array, each element of the array belongs to the same data type, You cannot add different types of data to an array.

Define array: type character array name [constant expression] (note: Constant expressions can be constants only and cannot contain variables when defined)

Eg:int Str[6] = {3,5,6,7,7,8};

(2) structure (struct): C language allows users to build their own data structure composed of different types of data, is the structure of the body.

When defining a struct, you first need to define the type of the struct, and then define the variable according to the struct type defined:

First step: Define the struct type: struct struct type name {member List};

Eg:struct student{int age; Char *name}; defines a struct with a type of Student, with two members in the struct;

Step two: Define variables: struct struct type name variable name

Eg:struct Student Stu defines a variable named Stu

Step Three: Assign a value to a variable: the name of the variable. Member name

Eg:stu.age = 19; Assigns a value to the age member in the struct

(3) Common Body (Union)

(4) enumeration (enum)

VI, no value type (void)

The value-free byte length is 0, there are two main purposes: one is to explicitly indicate that a function does not return any value; One is to produce a pointer of the same type (which can be dynamically allocated to its memory as needed). For example: void *buffer; /*buffer is defined as a non-value pointer */


The Dark Horse programmer--c Language Foundation--Data type

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.