C04 | Compilation and Execution of Programs

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

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

CODE | Ultrasonic Distance Alarm - Arduino Project 040

CODE | Ultrasonic Distance Alarm - Arduino Project 040

The sensor consists of two primary components: a transmitter and a receiver . The transmitter is res…

CODE | BMP280 Pressure Sensor LCD Display - Arduino Project 032

CODE | BMP280 Pressure Sensor LCD Display - Arduino Project 032

For this project we will use Arduino Uno and BMP280 along with LCD 16x2 display module to display te…

Arduino software Download

Arduino software Download

Arduino Web EditorStart coding online and save your sketches in the cloud. The most up-to-date versi…

Installing Redis on CentOS and Configuring Redis

Installing Redis on CentOS and Configuring Redis

CentOS安装Redis及redis启动与关闭、配置Install RedisIn this section you’ll add theEPEL repository, and then…

CODE | MX1508 H-Driver Motor - Arduino Project 030B

CODE | MX1508 H-Driver Motor - Arduino Project 030B

MX1508 H-BridgeDual Motor DriverThe driver can drive up to two motors. The H-Bridge dual motor drive…

Guide to UL Wire Specifications & Standards

Guide to UL Wire Specifications & Standards

Who is UL ?The UL enterprise is a global private safety company headquartered in Northbrook, Illinoi…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.