C04 | Compilation and Execution of Programs

RonWang4 years ago (2022-03-28)电子编程 COD29

C语言教程04:程序的编译与运行

源程序也称源代码,是指未编译的、按照一定的程序设计语言规范书写的文本文件,是一系列人类可读的计算机语言指令,可以用汇编语言或高级语言编写。计算机源代码的最终目的是将人类可读的文本翻译成为计算机可以执行的二进制指令,这种过程叫编译,通过编译器完成。不同的程序设计语言的源程序的扩展名是不同的,例如,用C语言编写的源程序,其文件扩展名为.c; 用 Java 语言编写的源程序,其文件扩展名为.java。

编译程序是将源程序译成能被CPU 直接识别的目标程序或可执行指令的程序。例如,用汇编语言书写的源程序要经过汇编程序译成用机器语言表示的目标程序,用高级语言书写的源程序要经过编译程序译成用机器语言表示的目标程序。

Execution-of-C-Program

目标程序是经编译程序翻译生成的程序,文件扩展名为.obj。

可执行程序是经连接程序处理过的程序,文件扩展名为.exe。

需要指出的是,源代码的修改不能改变已经生成的目标代码。如果需要目标代码做出相应的修改,必须重新编译。

C语言是一种通过编译程序处理的高级程序设计语言,其处理流程具体为 源程序(.c) -【编译】- 目标程序(.obj) -【连接】-可执行程序(.exe)。

(1) 编辑C语言程序:当确定了解决问题的方案后,可以用C语言系统提供的编辑功能编 写一个 C 语言源程序,源程序的扩展名为.c。

(2) 编译 C 语言程序生成目标程序:由于计算机只能识别和执行由 0 和 1 组成的二进制文件,而不能识别和执行用高级语言编写的源程序,所以必须先用 C 语言系统的编译程序(即编译 器)对其进行编译,以生成以二进制代码形式表示的目标程序,目标程序的扩展名为.obj。 

(3) 连接生成可执行程序文件:将目标程序与系统的函数库以及其他目标程序进行连接装 配,才能形成可执行程序文件,可执行文件的扩展名为.exe。 

(4) 运行可执行程序文件:将可执行程序文件(扩展名为.exe)调入内存并运行,得到程序的结果。

【例 1-7】求 3.5、4.6 和 7.9 这 3 个数的平均值。 

 #include <stdio.h>int main() { float x,y,z,aver; 
  x=3.5; 
  y=4.6;
  
  z=7.9; 
  aver=(x+y+z)/3; 
  printf("aver=%.1f",aver);
 return 0; }

程序运行结果

aver=5.3


Share with Friends:

Related Articles

The incredible growth of Python

The incredible growth of Python

Python is a powerful programming language and Big Scope of Python   Programming Language. Pytho…

About Arduino WIKI

About Arduino WIKI

Arduino (/ɑːrˈdwiːnoʊ/) is an open-source hardware and software company, project, and user community…

CODE | Liquid Crystal Displays-Serial to Display - Arduino Project 037

CODE | Liquid Crystal Displays-Serial to Display - Arduino Project 037

The DS18B20 Temperature Sensor is a digital temperature sensor capable of measuring temperatures wit…

CODE | LED Interactive Traffic Lights - Arduino Project 004

CODE | LED Interactive Traffic Lights - Arduino Project 004

This time you are going to extend the previous project to include a set of pedestrian lights and a p…

CODE | Piezo Sounder Alarm - Arduino Project 011

CODE | Piezo Sounder Alarm - Arduino Project 011

Arduino project - sounder and sensors : Include project 11 Piezo Sounder Alarm ,Project piezo sounde…

CODE | IR Remote Control Light - Arduino Project 050

CODE | IR Remote Control Light - Arduino Project 050

An IR remote and receiver communicate with each other by transmitting and decoding a signal in the f…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.