📜  源代码和目标代码之间的区别

📅  最后修改于: 2021-09-12 10:54:08             🧑  作者: Mango

1. 源代码:
源代码是指由人类/程序员生成的高级代码或汇编代码。源代码易于阅读和修改。它由程序员使用任何人类可读的高级语言或中级语言编写。源代码包含程序员为了更好理解而添加的注释。

源代码提供给语言翻译器,翻译器将其转换为机器可理解的代码,称为机器代码或目标代码。计算机无法理解直接的源代码,计算机理解机器代码并执行它。它被认为是计算机的基本组成部分。简单地说,我们可以说源代码是由程序员使用 C、C++、 Java、 Python、汇编语言等计算机编程语言编写的一组指令/命令和语句。因此,用任何编程语言编写的语句都被称为作为源代码。

2. 目标代码:
目标代码是指机器可以理解的低级代码。目标代码是从源代码经过编译器或其他翻译器后生成的。它是可执行的机器代码格式。目标代码包含一系列机器可理解的指令,中央处理单元可以理解和执行这些指令。

目标文件包含目标代码。它被认为是一种机器代码。一些目标文件示例是通用目标文件格式 (COFF)、COM 文件和“.exe”文件。它是编译器或其他翻译器的输出。我们可以理解源代码,但我们无法理解目标代码,因为它不像源代码那样是纯文本,而是二进制格式。

下图说明了源代码和目标代码:

源代码和目标代码的区别:

S.No. SOURCE CODE OBJECT CODE
01. Source code is generated by human or programmer. Object code is generated by compiler or other translator.
02. Source code is high level code. Object code is low level code.
03. Source code is written in plain text by using some high level programming language. Object code is translated code of source code. It is in binary format.
04. Source code is human understandable. Object code is not human understandable.
05. Source code is not directly understandable by machine. Object code is machine understandable and executable.
06. It is written in high level language like C, C++, Java, Python etc or assembly language. It is written in machine language through compiler or assembler or other translator.
07. It can be easily modified. It can not be modified.
08. It contains comments for better understanding by programmer. It does not contain comments for understanding by machine.
09. It contains less number of statements than object code. It contains more number of statements than source code.
10. It is less close. towards machine. It is more close towards machine.
11. Performance of source code is less than object code as it is less close towards machine. Performance of object code is more than source code as it is more close towards machine.
12. Source code is input to compiler or any other translator. Object code is output of compiler or any other translator.
13. Source code is not system specific. Object code is system specific.
14. It can be changed over time. Source code needs to be compiled or translated by any other translator to get modified object code.