0x01 overview, 0x01
Describes the C language's history, features, advantages and disadvantages, and other basic content.
C originated from Bell Labs and was developed in 1972. At that time, Dennis Ritchie and Ken Thompson designed UNIX systems together.
Features:
// Efficiency
Pointer: the pointer can be used to directly operate the data in the memory unit. You can also use the pointer to dynamically apply for memory resources from the system at any time as needed.
The time overhead and space overhead of the pointer mechanism are the smallest. Using the pointer mechanism, the C/C ++ language is highly expressive and can describe various complex data structures; allows you to operate on variables, functions, and objects.
Reference: A reference is the alias of a variable or object. (Keyword typedef) the reference is actually the reference address, so it is as efficient as the pointer. However, references overcome the inconvenience caused by pointers.
Inline functions: Generally, function calls require a certain amount of time overhead, which means that the call time is used to establish a call, pass a parameter, jump to the function code, and return the result. Well, it's equivalent to the enhanced version of # define.
// Portability
This means that C programs written on one system can run on other systems with few or no modifications. If modification is necessary, you only need to change the items in a header file that is accompanied by the main program.
// For programmers
The C language allows access to hardware and allows you to manipulate the special location in the memory.
The syntax of C is not as strict as that of other languages, but when using C, it may make some mistakes that do not occur in other languages. C has more freedom, but there is a greater risk when using it.
// Disadvantage
It has no boundary check, and is prone to memory conflicts, with floating pointers and memory/resource leaks. bolts support concurrency, no modules, and no namespace. Error Handling may be tedious and lengthy. When the call stack crashes or your processes are manipulated with aggressive input, a bunch of errors are easily generated.
The conciseness of C is combined with its rich operators, which makes it possible to compile extremely hard-to-understand code. C. There is also a risk of freedom of expression, and you may make very difficult-to-track programming errors. The cost of freedom is always vigilance.
C has security and reliability, but I don't want to continue with this topic.
The working principles of C language and computers are closely related. This also shows that learning C well also requires learning the microcomputer principle.
Cpu is very simple: Get an instruction from memory and execute it, then get the next instruction from memory and execute ......
The cpu work zone is in the register (registers), each register can only save one number.
The cpu can only understand limited commands (instruction sets, more content, learn to compile. This is why reverse engineering requires a certain amount of Assembly knowledge). These commands are quite specific, for example, moving a certain number from memory units to registers.
The following seven steps are required to write C Programs:
1. Define goals: At this stage, general concepts should be used to consider issues, rather than specific languages.
2. design a program: determine how the program achieves its goal, how the user interface is, how the program is organized, who the target user is, and how the time is planned. We also design algorithms and data structures.
3. Compile the code: select the programming language (C here of course) and the development environment (IDE? Or compiler + Text Editor ?), Code style and comments (do not look down on comments !!!) And so on.
4. Compile the code: this is the work of the Compiler (Compiler), which converts the source code into executable code. Another thing is called linker, which mainly introduces Library Routines to form an executable file that can run.
5. Run the program: directly click "Run" or "Run" in the IDE ". In the command line, go to the GCC compiler directory and type the executable file name. For example, in Linux, "gcc hello. c-o hello. out" and then "./hello. out"
6. Test and Debug: When the effect or result after running the program is not expected, check the code. Debug is also a technology. Do not continue here
7. Maintenance and modification: after the program is developed, there may be other improvements, bugs to be solved, or other functions to be added.
Programming cannot be like this ~ Items ~ Dragon down. Repeat the steps as needed. Or you have changed your mind and started working again. So,Make good planning before writing code.