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.
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.
2. Use the gcc cards.c -o cards command in the command prompt or terminal
3. Run the program by typing cards in the Windows command prompt or ./cards in the Mac and Linux terminal.
On most machines, you can use the following trick to compile and run the code:
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!
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!