1. Introduction
This course is intended for beginners, including those who have little or no programming experience. Intermediate programmers may find some suggestions and strategies to improve their programming skills.
Let's take a look at some of our goals:
1) covers all c ++ topics:
Compared with traditional books, this article covers programming styles, common traps, debugging, good/bad programming practices, and testing. You will know how to program with C ++.
2) provides a large number of reference examples:
The example demonstrates how to apply various concepts. Most people use examples to better understand the concepts learned.
3) provides exercise programming:
The best way to learn is to use the learned knowledge to compile your own program.
4) The most important thing is: Have fun.
Programming can produce a lot of pleasure. If you are always unhappy, it means you are not in the proper programming state.
2. Introduction to programming languages
Today's computers are getting faster and faster, but there are also obvious restrictions. The computer only executes limited commands mechanically. Software --
The Instruction Set that tells the computer how to operate. The hardware is the computer that executes commands mechanically.
1. Machine language:
The CPU of a computer does not speak C ++. What the CPU can understand is a very limited instruction set, called machine code, that is, machine language or instruction set.
First, an instruction consists of a set of binary digits. The values of each digit can only be 0 and 1. Generally, the instruction length of the x86 CPU is 32 bits, for example: 1011 0000 0110 0001.
Second, each binary bit set is translated from the CPU into an instruction.
Different CPU types have different instruction sets.
2. assembly language:
The assembly language was invented because programming in machine language is very difficult. Each Command is replaced by a short name, rather than a binary code, so it is easier to read and write.
The CPU cannot directly understand the Assembly Language and must be translated using a assembler. The assembly language is so fast that it is still used in demanding areas.
The assembly language is also used to write code for a specified CPU, and still requires a lot of operations and humanization.
Assembly commands such as mov Al and 061 H.
3. Advanced language:
To solve these problems, advanced languages, such as C, C ++, and Java, are generated. Advanced languages also need to be compiled and explained before the CPU runs.
Compiler: one-time compilation, which does not need to be re-compiled during runtime.
Interpreter: it is easier to write than the compiler, and the efficiency is low. Each time the program runs, it is required.
C and C ++ are compiled languages, while Perl and JavaScript are interpreted languages, while Java is compatible.
Advanced languages have the following features:
1) easy to read and write;
2) requires less command operations, such as A = B * 2 + 5. 5-6 steps are required in the assembly language;
3) do not pay attention to too much details, such as loading variables to CPU registers;
4) More importantly, it is suitable for CPUs with multiple structures.
3. C/C ++ Introduction
C language was invented by Dennis Ritchie in the Bell lab in 1972. Originally, it was a system programming language. Its main goal was to easily compile, efficiently access the memory, generate highly efficient code, and support it without runtime.
It can be said that it is a low-level high-level language and a platform independent language.
C language is so efficient and flexible. Ritchie and Ken Thompson used C to rewrite UNIX systems in 1973. The excellent compatibility of C language enables UNIX to be recompiled on different platforms.
The fate of C language is tied to Unix, and the popularity of C language is partly due to Unix as an operating system.
In 1983, ANSI forms the C standard, that is, the c89 standard; in 1990, ISO adopts the C standard, that is, the C90 standard; in 1999, the latest specified c99.
C ++ language is the extension of Bjarne stroustrup developed by Bell Labs in 1979. ISO 1998 and 2003 are approved by ISO; the latest standard is 2010 C ++ 0.x.
The potential design rules for C and C ++ are-trust programmers. This is one of the secrets of knowing how to program.
C ++ has added many features based on C. C ++ is an object-oriented programming language.
4. Development Introduction
Program Development flowchart:
Step 1: define the problem to be solved-What stage;
Step 2: Determine the solution to the problem-that is, the how stage:
A good solution includes the following features: intuitive, good writing, easy scalability, and modular. Achieving scalability and efficient modularization is a huge challenge.
20% principle-80% time to write code, and time to modify and debug code.
Modularization ensures code readability and reusability.
Step 3: write the code:
Requires programming language knowledge, programming tools; good programming tools: line numbers, syntax highlighting, different colors, determined fonts.
Step 4: compile:
Check whether the written code complies with the language specifications, and make the program input and output correctly.
Step 5: link:
Connect the target file to the relevant database to generate an executable file:
Command example: G ++-O prog file1.cpp file2.cpp file3.cpp
Step 6: Test and debug
Check whether the program running result is correct.
Generally, Steps 3-6 are continuously iterated.
5. Compile the first program:
Install different compilation tools based on different OS platforms.
First Program-classic helloworld
[Disclaimer:
1) This content may come from the Internet, or I have sorted it out by myself. It only represents the opinions and opinions of the Internet and individuals!
2) This content is for reference only. Any reference to this content will cause any consequences and will be irrelevant to the original author and the author of this blog.]