The difference between compiled language (C/C++) and interpreted language (Python)

introduce

insert image description here
insert image description here

principle

Compiled language:
Compiled language refers to the use of a special compiler to "translate" a certain high-level language source code for a specific platform (operating system) into a machine language that can be executed by the platform hardware (including machine instructions and Operand), and packaged into an executable program format (such as .exe file) that the platform can recognize, this conversion process is called Compile. The executable program generated by compilation can run independently on a specific platform without the development environment.

Interpreted language:
An interpreted language refers to a language that uses a special interpreter to interpret the source program line by line into machine code for a specific platform and execute it immediately.

Recall that C/C++ needs to be compiled and executed before running, while python can be executed sentence by sentence on the command line, and no .exe file will be generated in the end.

For compiled languages ​​(such as C language), we only need to install a compiler, but for interpreted languages, we not only need to install a specific compiler, but also a specific installation environment.

the difference

  1. C++ is efficient but difficult to program; python is inefficient and easy to program. For the same function, perhaps python can write code very quickly, but the time required to run it needs to be doubled in C++. Python is a scripting language that is interpreted and executed without compiling, so it is very convenient and fast, and it can cross-platform very well. It is especially suitable for writing some small tools and small programs.
  2. A compiled language is compiled into machine code once, so it can run independently from the development environment, and usually has a high operating efficiency; an interpreted language needs to be compiled every time a program in an interpreted language is executed, so a program in an interpreted language The operating efficiency is usually low, and it cannot be run independently without the interpreter. But an interpreted language has an advantage: cross-platform is relatively easy, just provide a platform-specific interpreter, and the interpreter on each specific platform is responsible for interpreting the source program into platform-specific machine instructions. For example, in Java, we will generate a .class bytecode file at runtime, and then convert it into machine code for a specific platform
  3. Python is interpreted and executed, and there is an interpreter layer between the CPU of the physical machine, while C++ is compiled and executed, which is directly machine code, and the compiler can perform some optimizations during compilation. Therefore, in terms of operating efficiency, C++ is much better than python.

Guess you like

Origin blog.csdn.net/weixin_45184581/article/details/124021113