欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

c语言用命令行编译运行程序_编译并运行C程序

程序员文章站 2022-06-05 16:44:56
...

c语言用命令行编译运行程序

编译并运行C程序 (Compile and Run C Program)

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.

    或者,您可以使用任何文本编辑器来编辑程序文件并分别下载C编译器。

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(集成开发环境),单击“ 文件” ,然后单击“新建”

c语言用命令行编译运行程序_编译并运行C程序

Step 2 : Write the above example as it is

步骤2:照原样编写上面的示例

c语言用命令行编译运行程序_编译并运行C程序

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

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

c语言用命令行编译运行程序_编译并运行C程序

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

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

c语言用命令行编译运行程序_编译并运行C程序

Step 5 : Output

步骤5:输出

c语言用命令行编译运行程序_编译并运行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/

如果您不希望安装IDE并希望采用旧的方式,请从gcc网站https://gcc.gnu.org/install/下载名为gcc的C编译器。

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

下载并安装gcc编译器后,您需要做的所有事情,打开任何文本编辑器,复制并粘贴上一教程中的C程序代码,然后将其保存为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

Hello,World

你好,世界

编译和运行之间的区别 (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.

当我们运行一个已编译的程序时,它实际上会执行main()函数中的语句。

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

c语言用命令行编译运行程序