C Language Learning Tutorial Chapter II-Data types, operators, expressions (i)

Source: Internet
Author: User
Tags constant function definition integer variables sin valid

C-Language data types

In the first lesson, we have seen that the various variables used in the program should be described in advance, that is, before use. The description of a variable can include three aspects:
• Data type
• Storage Type
• scope
In this lesson, we'll just describe the data type description. Other explanations are introduced in the following chapters. The so-called data types are classified by the nature of the description, the representation, the amount of storage space, and the structural features. In C, the data type can be divided into: basic data type, construct data type, pointer type, empty type four kinds.

1. Basic data types

The primary characteristic of a basic data type is that its value can no longer be decomposed into other types. In other words, the basic data type is self explanatory.

2. Construct data type construct data type

is defined by a constructed method based on one or more data types that have been defined. In other words, the value of a constructed type can be decomposed into several "members" or "elements". Each member is a basic data type or another constructed type. In the C language, there are several types of constructs:
• Array type
• Structure type
• Union type

3. Pointer type

A pointer is a special type of data that has an important role to play. The value is used to represent the address of a certain amount in the memory. Although the value of a pointer variable is similar to an integral type, it is a completely different amount of two types and cannot be confused. 4. A null type typically returns a function value to the caller when calling the function value. The returned function value is of a certain data type, should be explained in function definitions and function descriptions, such as in the Max function definition given in the example, the function header is: int max (int a,int b), where the int type specifier indicates that the return value of the function is an integer. Also, as in the example, the library function sin is used, because the system stipulates that its function return value is a double-precision floating-point type, so in the assignment statement S=sin (x), s must also be a double-precision floating-point type to match the return value of the SIN function. So in the Description section, the S is described as a double-precision floating-point type. However, there is a class of functions that do not need to return function values to the caller, which can be defined as "null type." Its type descriptor is void. In the fifth chapter, the function should also be described in detail. In this chapter, we first introduce the integral, floating-point, and character types in the base data type. The remaining types are introduced in subsequent chapters.

For the basic data type quantity, according to its value can be changed and divided into constant and variable two kinds. During program execution, the amount of the value that does not change is called a constant, and the variable value is called a Variant. They can be categorized in combination with data types. For example, you can divide into integer constants, integer variables, floating-point constants, floating-point variables, Word constants, character variables, enumerated constants, enumeration variables. In a program, a constant can be directly referenced without explanation, and a variable must be described before use.

Integral type Quantity

Integer types include integer constants, integer variables. An integer constant is an integer constant. In the C language, the integer constants used are eight, hexadecimal, and decimal three.

Integral type Constants

1. Eight-integer constant octal integral constant must start with 0, that is, 0 as the prefix of octal numbers. The digital value is 0~7. The octal number is usually unsigned.
The following numbers are valid octal:
015 (decimal 13) 0101 (decimal 65) 0177777 (decimal is 65535)
The following numbers are not legal octal:
256 (without prefix 0) 03a2 (contains octal digital)-0127 (minus sign appears)

2.16 in-process integer constant
The hexadecimal integer constant has a prefix of 0X or 0x. Its digital value is 0~9,a~f or a~f.
The following numbers are valid hexadecimal integer constants:
0X2A (decimal) 0xa0 (decimal 160) 0XFFFF (decimal 65535)
The following numbers are not valid hexadecimal integer constants:
5 A (no prefix 0X) 0x3h (contains non-hexadecimal digits)

3. Decimal integer constant
The decimal integer constant has no prefix. Its digital is 0~9.
The following numbers are valid decimal integer constants:
237-568 65535 1627
The following numbers are not valid decimal integer constants:
023 (cannot have leading 0) 23D (contains non-decimal digits)

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.