C primer plus 1 Chapter 2 Notes

Source: Internet
Author: User

Overview and C language description

Main content:

Historical Features of C

Procedure

Compiler and linker knowledge

C standards

Operator =

Function main () printf ()

Write a simple C program

Create an integer variable to assign values to it and display it on the screen

Newline character

How to add comments to a program, create a program containing multiple functions, and find out the errors

Understanding what is a keyword

I.

  1. Dennis Ritchie of Bell's lab developed C in 1972, but C was not entirely conceived by Ritchie, and it came from B.
  2. C features: high efficiency; portability; powerful functions and flexibility; oriented to programmers. Kim has no foot in the dark, and he also has some disadvantages: its freedom of expression will increase the risk, especially the use of pointers will make it difficult to trace programming errors; the conciseness of C combined with its rich operators makes it possible to compile extremely difficult-to-understand code.
  3. C language development direction: Lucas movies, UNIX operating systems, computer games, embedded systems, robot factories, Star Wars movies, PC applications, computer languages, etc.
  4. Basic working principle of computers: modern computers can be divided into (Central Processing Unit (CPU), random access memory (RAM), permanent storage (usually hard disk ), there are also various peripheral devices (mouse and keyboard display )).
  5. Seven steps to use C language: Define the program target, design the program, write the code, compile and run the program, test and debug the program, maintain and modify the program.
  6. The basic policy of C programming is to convert the source code file to an executable file, which contains the executable machine language code. C completes this step in two steps: the compiler converts the source code into intermediate code, and the linker combines the intermediate code with other code to generate an executable file.
  7. Language Standard: ANSI/iso c standard the final version of this standard is referred to as c89 or C90. However, because ANSI is the first version, ansi c is usually used.

II.

1. # include <stdio. h> This is an example of the C Preprocessor command, stdio. H (standard input/output header) This file is a header file that contains information about input and output functions.

2. a c program of the main () function is always executed from the main () function.

3. note two situations: 1 /**/

It can also be divided into two rows /*

*/

Second, // This annotation is restricted to a row.

4. Statement

For example, if int num int is the keyword (the Blue font is displayed when the keyword is written) num is the variable declaration variable num, the compiler will allocate a suitable storage space for num. Data Types, as the name implies, are designed to differentiate various types of data. Different Data Types in C have different precision (for example, float and double types have different precision decimal places) and have different processing methods.

When declaring a variable, You must select the correct name. It can only contain letters, numbers, and underscores (_). The first character must be a letter or underscore.

5. Use "=" to assign values. Note that the latter is an arithmetic operator.

6. printf () function

For example, printf ("My favorite num is % d \ n", num );

% D is a placeholder for printing the num value here

\ N is a line break. When you press enter, a new line starts.

 

  1. Debug (debugging)

Program errors are often called bugs (from the legend of the Bug)

Errors in a program are generally divided into syntax errors (for example, if a symbol or a wrong position is missing, it is easy to ignore the semicolon, it is easy for beginners to add a semicolon after the loop statement to make it difficult to find errors) semantic Error (this refers to the fact that you follow the rules when writing code, but the meaning is wrong. For example, if you require a cube but write it as a * a, this compiler is hard to find ).

  1. C language keywords
  2. Auto: automatic variable declaration is generally not used
  3. Double: Declares double-precision variables or functions.
  4. INT: Declares integer variables or functions.

    Struct: Declares struct variables or functions.

    Break: jump out of the current loop

    Else: The Condition Statement denies the branch (used with if)

    Long: declares a long integer variable or function.

    Switch: Used for the switch statement

    Case: switch statement Branch

    Enum: Declares the enumeration type.

    Register: declare the memory variable

    Typedef: Used to get an alias for the data type (of course there are other functions)

    CHAR: declare struct variables or functions

    Extern: declared variables are declared in other files (or can be seen as referenced variables)

    Return: subprogram Return Statement (which can contain parameters or not)

    Union: Declares the Union data type.

    Const: declare Read-Only variables

    Float: Declares floating point variables or functions.

    Short: declare short integer variables or functions

    Unsigned: Declares unsigned type variables or functions.

    Continue: ends the current cycle and starts the next cycle.

    For: a loop statement)

    Signed: life-Signed type variable or function

    Void: declares that a function has no return value or no parameter and has no type pointer (basically, these three functions)

    Default: "other" branch in the switch statement

    Goto: unconditional jump statement

    Sizeof: calculates the length of the data type.

    Volatile: indicates that variables can be implicitly changed during program execution.

    Do: the body of the loop statement.

    While: the loop condition of the loop statement

    Static: declare static variables

    If: Condition Statement

     

 

 

C primer plus 1 Chapter 2 Notes

Related Article

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.