Apply for Zend Framework Certification Training

c



< c compiler installation How to print in c in different ways >



Compile a C file using its filename

To compile a C file using its filename, you normally use a C compiler such as GCC.
Suppose your C file is named:
program.c
1. Compile the C file
Open Command Prompt / Terminal and type:
gcc program.c
This creates an executable file.
On Windows, the default executable is usually:
a.exe
Run it with:
a.exe
or:
.\a.exe
2. Give your executable a specific name
You can use the -o option:
gcc program.c -o program
Then run:
Windows:
program.exe
Linux/macOS:
./program

what is gcc in c
GCC stands for GNU Compiler Collection. It is one of the most widely used compilers for the C programming language (and also supports C++, Java, Fortran, Ada, Go, and others).
In C programming, GCC takes your source code (written in .c files) and converts it into an executable program that your computer can run.
How GCC works
Suppose you have a file named hello.c:
#include <stdio.h>
int main() {
    printf("Hello, World!\n");
    return 0;
}
Compile it using GCC:
gcc hello.c -o hello
gcc → Runs the GCC compiler.
hello.c → The C source file.
-o hello → Names the output executable hello.
Run the program:
On Linux/macOS:
./hello
On Windows:
hello.exe
Output:
Hello, World!
Stages of GCC compilation
When you compile a C program, GCC performs several steps:
Preprocessing
Processes #include, #define, and other preprocessor directives.
Compilation
Converts C code into assembly language.
Assembly
Converts assembly code into machine code (object files).
Linking
Combines object files and libraries into the final executable.
Common GCC commands
Compile a program:
gcc program.c
Specify the output file:
gcc program.c -o program
Enable all common warnings:
gcc -Wall program.c -o program
Compile with debugging information:
gcc -g program.c -o program
Optimize the program:
gcc -O2 program.c -o program
Why use GCC?
Free and open source
Fast and reliable
Supports multiple programming languages
Available on Linux, macOS, and Windows (via MinGW or MSYS2)
Widely used in industry, education, and open-source projects
In short, GCC is the software that translates your C source code into a machine-executable program. Without a compiler like GCC, the computer cannot directly run C code.

< c compiler installation How to print in c in different ways >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top