Basic review of C language

Source: Internet
Author: User

Chapter I. C Language Basics

1. C Language compilation process

Preprocessing: Macro substitution, conditional compilation, header file inclusion, special symbols

Compile, optimize: translate and optimize to equivalent intermediate code representation or assembly code

Assembly: The machine language code that generates the target file, and the target equivalent to the source program, is composed of at least the code snippet and data segment

Link: Connect the relevant target files to each other, and divide them into static and dynamic links

2. Coding Specifications

(a) appropriate annotations;

The "{" and "}" exclusive lines and align pairs, the code within the "{}" is indented 4 spaces to the right, and if, for, while and other keywords leave a space followed by "(", but the function follows;

"(" to follow; ")", ",", ";" forward;

"," After a blank, ";" Not a blank at the end of a line;

The binary operators are appropriately plus spaces on both sides, but the monocular operator and the "[]", ".", "," are followed;

Wrap lines appropriately when one line of code is too long

3. Keywords

data types: int, char, float, double, short, long, Void, signed, unsigned, enum (enum type), struct (struct), Union (Union), const ( Read-only variable), typedef (type definition), volatile (more for embedded development, indicating that this variable can be implicitly changed, so that the optimizer will reread the variable every time it is used instead of using the value in the register)

Storage Category: Auto (auto), static (internal), register (register), extern (external)

Statement command word: Break (jump out of switch and this layer loop), case, continue (judging from the condition of this cycle into the next loop), default, do, else, for, Goto, if, renturn, switch, while

Operator: sizeof

4. identifiers

start with a letter or "_", which can consist of letters, numbers, "_"

5. Constants

constants can be modified with "U", "U", "L", "L", octal number starts with "0", Hex starts with "0x", "0X", and the symbol constants are quoted in single quotation marks, string constants are enclosed in double quotes, and note that string constants occupy space as String length plus one byte

6. Data Type

Tc/byte Vc/byte

[Signed] int 2 4

unsigned [int] 2 4

[Signed] short [int] 2 2

unsigned short [int] 2 2

[Signed] long [INT] 4 4

unsigned long [int] 4 4

Float 4 4

Double 8 8

Char 1 1

Signed Char 1 1

unsigned char 1 1

Typedef:typedef a new name for the type name, the typedef executes at compile time and the macro executes at preprocessing time

typedef declares an array type: such as typedef int ARR[10], so that "arr A;" and "int a[10];" Equivalent

Enum Type:

Enum enum Name

{

identifier [= Symbol constant],

......

identifier [= Symbol constant],

}[variable name];

Shared body:

Union shared nomination

{

Data type identifier;

......

Data type identifier;

}[variable name];

7. Storage type of variables

Local variables: Variables that are defined in a function (including the main function) or in a compound statement only work in this function or compound statement, which is also called an internal variable

Global variables: Variables defined outside the function, at the time of definition to the end of the source file function, if the global variable and local variable name (the same function is not the same variable, but different functions can), the local variable function, the same name global variable temporarily does not work

Static storage variables: stored in static storage, allocating space at compile time and assigning initial value, no initial value assigned 0, including global variables and local static variables (corresponding to automatic variables, with static)

Dynamic Storage variables: Store in dynamic storage, allocate space and assign initial value at function call, no initial value is random number, including formal parameter and automatic variable (local variable, auto)

Chapter II operators and Expressions

1. precedence of Operators

1 : () [].

2  :! ~ + +---+ * & (type character) sizeof (all monocular operators)

3 :*/%

4 :+-

5 :<< >>

6 :< <= > >=

7 := = = =

8 :&

9 :^

Ten :|

One:&&

:| |

:? :

:= = = = *=/=%= >>= <<= &= |= ^= (all assignment operators)

:,

where only the assignment operator, the conditional operator (trinocular), the monocular operator are right-associative

2. The value of an expression

Assignment expression: The value assigned to the variable

Conditional operator: According to "? "Before expression Select": "The value of an expression on either side of

Comma expression: The value of the last expression comma-delimited

Chapter III function

1. internal and external functions

use static to declare (define) an intrinsic function that can only be called by a function of the same source file, without worrying about the same name as other file functions; extern can declare (define) external functions, where extern can save

2. parameters of the main function

Main (int argc, char *argv[]), when you call main when you enter "filename str1 str2 ..." on the command line, ARGC is the number of arguments, including the filename, argv points to str1, str 2 ...

Fourth Chapter Pointers

1. pointers to Strings

Char *p= "Hello world."; Medium p points to a string constant, not a string to the memory that P points to

2. several definitions

int *p; Pointer to integral type

int (*p) [n]; Pointer to n-length one-dimensional array

int *p[n]; N-length pointer array to integer

Int (*p) (); Pointers to functions

int *p (); Integer pointer type function, function return value is integer pointer

int **p; A second-level pointer to a pointer to an integer pointer, and a pointer to a one-dimensional array

3. ". "and" - "The Difference

“.” A struct or union used to bring up a member, with a struct variable or a union variable, and with a pointer to a struct variable or a union variable, they cannot be interchanged (plus "*")

4. Const and Pointers

(const int *) and (int *) are not of the same type, which can be converted automatically to the former, which cannot be converted to the latter by an automatic type. Note the difference between (const int *) and (int * const), which is a pointer to a constant, which is a constant pointer to a variable. The (const int *) variable cannot be changed by a dereference, but it can change the value of the variable. The (int * const) variable cannot be changed, but it can change what it refers to. You typically declare a function parameter as const or point to a cosnt pointer, avoiding changing the value of a parameter or the value it refers to.

Fifth Chapter pretreatment

1. pre-processing functions

Macro definitions, file inclusions, conditional compilation, all with "#"

2. Example

#define, macro definition, with parameter attention Plus "()", and #undef mates

#include, the file contains, "<>" means to find only in the standard library, and "" ", first found in the current directory is not found to the standard library

#if ...

......

#elif

......

#else

......

#edif

#ifdef: When defined by a macro

#ifndef: When not defined by a macro

#line: #line line number ["FileName"]

#pragma: The following three types of parameters

message, output the appropriate information in the Compile Information Output window

Code, set the snippet where the function code is stored in the program

Once, ensure that header files are compiled once

3. Special Macro Definitions

__line__, __file__, __date__, __time__, __stdc__, __cplusplus, etc.

Sixth Chapter Common algorithms

1. Sorting

2. Find

3. Data compression

Reference documents

C Language Development Practical treasure/Liu Binbin, davidwong and other authoring. -Beijing: Tsinghua University Press, 2011.1

C language Programming Tutorial/Li Ling, Gui Jean, Liulianying authoring. -Beijing: People's post and telecommunications press, 2005.2

C Function Quick Check manual/Yundechun authoring. -Beijing: People's post and telecommunications press, 2009.4

C language Advanced Programming/Chen Tianzhou authoring. -Beijing: People's post and telecommunications press, 2002.12

C Language Algorithm Quick Search manual/Peter and other authoring. -Beijing: People's post and telecommunications press, 2009.10

C language programming of the Tao/Liu Binbin, Sun Shumei, Li Xin Authoring. -Beijing: People's post and telecommunications press, 2011.3

Basic review of C language

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.