Home >Backend Development >C#.Net Tutorial >How to run programs in c language in gcc?

How to run programs in c language in gcc?

烟雨青岚
烟雨青岚Original
2020-07-06 10:30:354788browse

How to run a program in gcc using c language: 1. Save the code to be run in a file called "cards.c"; 2. Enter "gcc cards.c -o cards" in the command prompt " command and press Enter; 3. Enter the "cards" command in the command prompt and press Enter to run the program.

How to run programs in c language in gcc?

C language is a compiled language, which means that the computer will not directly interpret the code, but needs to convert the source code for human reading (or Compiled) into machine code that the machine can understand so that the computer can execute it.

In order to compile the code, a program called a compiler is needed. GNU Compiler Collection, also called gcc, is one of the most popular C compilers. gcc can be used in many operating systems, and in addition to C language, it can compile many other languages. The most important thing is that it is completely free.

The following is how to compile and run the program with gcc:

1. Save the code in the "Code Fridge Magnet" exercise on the previous page In a file called cards.c.

How to run programs in c language in gcc?

2. Use the gcc cards.c -o cards command in the command prompt or terminal

How to run programs in c language in gcc?

3. Run the program by typing cards in the Windows command prompt or ./cards in the Mac and Linux terminal.

How to run programs in c language in gcc?

On most machines, you can use the following trick to compile and run the code:

How to run programs in c language in gcc?

This command It will only run the new program if the compilation is successful. If something goes wrong during the compilation process, it will skip running the program and just display an error message on the screen.

Now you should create the cards.c file and compile it. As this chapter unfolds, we will gradually improve upon it.

Let's see if the program compiles and runs successfully. Open a command prompt or terminal on your machine and give it a try!

How to run programs in c language in gcc?

Recommended tutorial: "C Language"

The above is the detailed content of How to run programs in c language in gcc?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn