Location>code7788 >text

Linux operating system and file system, common commands (below)

Popularity:63 ℃/2024-09-25 10:24:23

The vast majority of the C language should be recorded in files with .c as the extension, which are called C source files.

C programs also include files with .h as an extension, which are called header files (only a very small amount of content can be recorded in a header file)

C programs can use numbers and the four operation symbols of addition, subtraction, multiplication and division (* for multiplication and / for division).

Every computational step in a C program must be terminated with a semicolon, and every computational step terminated with a semicolon is called a statement.

The vast majority of C statements must be written between curly braces.

Braces can be used to represent functions in C programs (functions can be thought of as a set of statements)

Each function must have its own name, different functions cannot have the same name

A C program must contain a function called main; this function is called the main function.

A C program must be executed from the first statement of the main function, and the program ends after the last statement of the main function.

At the end of a function you can indicate the result of your work with a number, which is called the return value of the function.

The main function should have a return value, if this return value is 0 means that the program wants the computer to think that he ended normally, if it is not 0 means that the program wants the computer to think that he has a problem

The C language reserves dozens of English words, which are called keywords

Each keyword has a specific purpose and should not be used arbitrarily

All keywords are made up of lowercase English letters

return is a keyword that serves two purposes; the primary purpose is to end the execution of the function, and the secondary purpose is to specify the value of the return value (only writing a number after the keyword serves as a secondary purpose)

The computer divides different numbers into groups based on how they differ in some way, and each group is called a data type

Each data type has a name

The integer type is a data type whose name is int

This data type contains almost all numbers without a decimal point.

Numbers used in a program must have a data type. Numbers without a decimal point in C are integers by default.

If the function has a return value, you must write the name of the type of the return value before the function name.

  C Program Coding Code

  1. A line contains at most one statement, and a statement can occupy more than one line.

  2. The leftmost column of statements contained in the same pair of curly braces should be aligned up and down.

  3. Use spaces and blank lines where appropriate.

  C programs usually contain preprocessing instructions. Preprocessing instructions begin with #; they do not end with ;.

  The preprocessing instructions encountered in standard C can replace the contents of a file with something else.

  The #include preprocessor directive can include the contents of a header file in the current file.

  This preprocessor usually uses a relative path to indicate the location of the included header file.

  If the relative path is included in <>, it means that a predefined set of directories in the system is used as the starting point of the relative path.

  If the relative path is included in the middle of "", it means that the current file directory is the starting point, and then a predefined set of directories in the system is used as the starting point in turn.

C programs can include textual explanatory information, which must be added to the comment field; the computer simply ignores the contents of the comment field.

  Single-line comments begin with // and continue to the end of the line.

  Multi-line comments begin with /* and end with */.
  Conditional compilation #if
          #endif

C programs make extensive use of names to distinguish between different contents, which are called identifiers

When writing identifiers, it is best to use the rules for writing English word identifiers

1. The first character should be an English character or an underscore

2. Each subsequent character can be an English letter, an underscore, or an Arabic numeral.

3. Case-sensitive identifiers are different identifiers (case-sensitive)

4. Keywords can not be used as identifiers

5. There is no limit to the length of the identifier, the computer will only intercept the first part of use

6. Identifiers should be written in camel case (alternating upper and lower case) or underscore case (underlined to differentiate).

Compilers can translate written documents into a format that a computer recognizes

gcc is a C program compiler for Linux.

MingGW is gcc for windows.

Basic Steps for C Program Development on Linux Systems

1. Use vim or vi to write source files and header files.

2. Use the gcc command to translate all source files into a computer-recognizable format (compilation).

3. Use . / as the result of the execution of the command to get the file

Steps of the gcc compiler

1. Process all preprocessing instructions

2. Translate the results of the first processing step into a format recognized by the computer (compilation)

3. Combine the results of the second step of processing into an executable file (linking)

Introduction to gcc Command Options

-E Processes only preprocessing instructions

-c Processes only preprocessing instructions and compilation work; results in a target file with .o extension

-o is used to specify the name of the resulting file

-std=c89/-std=c99

This is used to specify what version of the specification will be used for this compilation; the default is to compile using the c89 specification.

Assignment: write a program to calculate the price of breakfast

2 doughnuts and a bowl of soymilk. 2 yuan for a doughnut and 5 yuan for a bowl of soymilk.