2, C language--c language composition and data

Source: Internet
Author: User
Tags arithmetic arithmetic operators

C Language Composition and data

Composition structure:
Composition: Several documents
Files: Several functions
Function: function header + function end
Function Header: Four section, function name + ()
Function Body: {}+ statement
Statement: Class three statements
Type 1->/* */
Type 2-> definition statement;
Type 3-> execution statement;

Data and data types

Data four categories: constant variable expression functions and precompilation
Constant: The amount of value that does not change
Variable: The amount of change in value anywhere
Expression: A legal formula for connecting data with an operator
Functions: Call functions with functions as operands

Data types Four categories: base type, constructed type, pointer type, NULL type
Base type: int, char char, floating point (single float, double type) enum enum
Constructed type: array type, struct type struct, common body type Union
Pointer type:
Empty type: void

Identifiers (three types)
1, Reserved words (keywords): A total of 32, fixed meaning, can not be used for it
such as: int float char if else for
2. Predefined identifiers: Identifiers that are predefined in the C language and have a specific meaning
scanf printf include
3. User-defined identifiers: identifiers defined by the user as needed. such as: variable name, array name, function name, etc.
Note: (1) User-defined identifiers,
Identifiers can only consist of letters, numbers, underscores, and the first character must be a letter or an underscore
(2) In C programs, uppercase and lowercase letters are strictly differentiated. such as the int int sum sum,c language program mainly uses lowercase.

Data and data types
Data four categories: constant variable expression functions
Constant Class Four:
Integral type constant
Three types (decimal, octal, hex)
The first form, the decimal: is a series of consecutive 0 ... 9 numbers
The second form, octal: A string of consecutive legal octal characters starting with the number 0
The third form, 16 binary: A string of consecutive valid hexadecimal characters beginning with 0X or 0x
If you indicate a long integer constant, you must add the letter L or L

Real-type constants
Two forms (decimal, exponent)
First form, decimal form: Composed of numbers and decimal points
The second form, exponential form: followed by an integer with "E" or "E" to indicate a power of 10
Note:
(1) the letter E or E must be preceded by a number, and the following shall be an integer
(2) There must be no spaces between the letters E or E and the numbers

Character-type constants
Four forms (regular, escaped, octal, hex)
First form-a pair of single quotes enclose a character
Second form, escape character constant: must begin with a backslash "\"
\ n indicates a newline character.
\ t represents a tab
\b says backspace
\ r indicates a carriage return character
Third form->\ddd up to three octal digits
The four-form->\xhh can have up to two hexadecimal digits

String constants
A form
Definition: Use a pair of double quotation marks (double apostrophes) to enclose several characters.
Note:
(1) Each string end has a string Terminator '
(2) There is no string variable in C language
Be sure to differentiate between character constants and string constants

Variable
Variable usage rules: first defined and then used
Definition Format: List of data type name variable names
Note:
(1) Variables must be defined before use
(2) Variable name belongs to user identifier, abide by user identifier naming rules
(3) A variable with the same name cannot be defined in the same "function body" {}
(4) Define multiple variables at the same time, must be separated by commas
(5) Variable can be assigned initial (initialization), no initial value is random values

Function
function (Standard function Custom function)
Can participate in the operation

An expression
1. Definition: expression: A legal formula for connecting data with operators
Operator: Three properties: function, priority, binding (direction of operation)

Arithmetic operators and arithmetic expressions:
+ - * / %

Redundancy (%):
(1) Both operands must be integral type
(2) Evaluation method: First ignore the minus sign to find the remainder, and then the remainder of the symbol to be the same as the divisor of the symbol can be
Note:
(1) A separate constant, variable, or function call is a C-language legal expression
(2) All expressions are a definite value.

2. Assignment operators and Assignment expressions
Assignment operator: =
Format: variable name = expression

function of the assignment operator: assigns the value of an expression to the variable to the left of "="
Note:
(1) Only one variable to the left of the assignment operator
(2) The right of the assignment operator can be a legal expression
(3) The value of an assignment expression is the left variable value of the assignment operator.
(4) When the real data is assigned to an integer variable, the real decimal is given away; When the integer data is assigned to the real variable, the system automatically transfers the integer data to the Narimi type data

Compound assignment operators:
+ =,-=, *=,/=,%=, &=, |=, ^=, >>=, <<=
Note: There can be no spaces in the middle of the two operators of the compound assignment operator

3, self-increment, decrement operator
Note: (1) Only variables cannot be used for constants or expressions

4. Comma operator and its expression ("order evaluation" expression)
Format: expression 1, expression 2, expression 3, ... Expression n
Function: The value of the comma expression is the value of the expression n (the last expression), and the Order of evaluation is solved from left to right

Forcing type conversions (explicit conversions)

Format:
(type name) expression or (type name) (expression)
Use the coercion type conversion operator to convert the value of an expression to a specified type
Casts a forced type, resulting in an intermediate value, and the type of the original expression or variable has not changed

Such as:
If the variable x is of type int, the result of the expression (float) x is a single-precision type, but X is also of type int

The composition of C language
Signs of the form:
(){}
“” ‘’
\\0
l#
0x;
0

Flags of the operation:
++
--
=

2, C language--c language composition and data

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.