How to compile a C program?

To compile a C program, you typically use the gcc (GNU Compiler Collection) command. Here’s a step-by-step guide:

  1. Write Your C Code: Create a C source file, for example, program.c.

  2. Open Terminal: Navigate to the directory where your C file is located.

  3. Compile the Program: Use the following command:

    gcc program.c -o program
    
    • gcc: The compiler command.
    • program.c: Your C source file.
    • -o program: This option specifies the name of the output executable file (in this case, program).
  4. Run the Compiled Program: After successful compilation, run the program using:

    ./program
    

Make sure you have gcc installed on your system. If you need help with installation or have any other questions, let me know!

0 Comments

no data
Be the first to share your comment!