To compile and run a C language program, you need a C compiler. To setup a C language compiler in your Computer/laptop, there are two ways:

要编译和运行C语言程序,您需要C编译器。 要在您的计算机/笔记本电脑中设置C语言编译器,有两种方法:

  1. Download a full fledged IDE like Turbo C or Microsoft Visual C++, which comes along with a C language compiler.

    下载功能完善的IDE,例如Turbo C或Microsoft Visual C ++,它随附C语言编译器。

  2. Or, you use any text editor to edit the program files and download the C compiler separately.


Here we have a simple video, explaining how to setup Tubrbo C/C++ for writing, compiling and running C programs.

在这里,我们有一个简单的视频,解释了如何设置Tubrbo C / C ++来编写,编译和运行C程序。


使用IDE-Turbo C (Using an IDE - Turbo C)

We will recommend you to use Turbo C IDE, oldest IDE for c programming. It is freely available over internet and is good for a beginner.

我们建议您使用Turbo C IDE(最古老的IDE进行c编程)。 它可以通过互联网免费获得,对初学者来说非常好。

Step 1 : Open turbo C IDE(Integrated Development Environment), click on File and then click on New

第1步:打开turbo C IDE(集成开发环境),单击“ 文件” ,然后单击“新建”

first c program with turbo C

Step 2 : Write the above example as it is


Write a C program with turbo C

Step 3 : Click on compile or press Alt+f9 to compile the code

步骤3:点击编译或按Alt + f9编译代码

Compiling a C program with turbo C

Step 4 : Click on Run or press Ctrl+f9 to run the code

步骤4:按一下[执行]或按Ctrl + f9键来执行程式码

Running a C program with turbo C

Step 5 : Output


Output of C program with turbo C

没有IDE (Without an IDE)

If you do not wish to setup an IDE and prefer the old school way, then download the C compiler which is called gcc from the gcc website https://gcc.gnu.org/install/


Once you have downloaded and installed the gcc compiler, all you have to do it, open any text editor, copy and paste the C program code from the previous tutorial, and save it with the name hello.c


Open Command prompt or Terminal(if you use Ubunut or Mac OS), and go to the directory where you have saved the hello.c program file.

打开命令提示符或终端(如果使用Ubunut或Mac OS),然后转到保存hello.c程序文件的目录。

Type the command gcc hello.c to compile the code. This will compile the code, and if there are no errors then it will produce an output file with name a.out(default name)

键入命令gcc hello.c来编译代码。 这将编译代码,并且如果没有错误,则将生成名称为a.out (默认名称)的输出文件。

Now, to run the program, type in ./a.out and you will see Hello, World displayed on your screen.

现在,要运行该程序,请输入./a.out ,您将在屏幕上看到Hello,World

$ gcc hello.c
$ ./a.out



编译和运行之间的区别 (Difference between Compile and Run)

You must be thinking why it is a 2 step process, first we compile the code and then we run the code. So, compilation is the process where the compiler checks whether the program is correct syntax wise, and there are no errors in the syntax.

您必须考虑为什么这是一个两步过程,首先我们编译代码,然后运行代码。 因此,编译是编译器检查程序是否正确语法(语法正确)并且语法没有错误的过程。

When we run a compiled program, then it actually executes the statements inside the main() function.


翻译自: https://www.studytonight.com/c/compile-and-run-c-program.php



  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
©️2022 CSDN 皮肤主题:编程工作室 设计师:CSDN官方博客 返回首页
钱包余额 0