C Weekly | How to compile C Program

 Hello everyone,
Welcome to my blog "C Weekly". Let's start today's topic - "How to compile C Program".
As we all know that C is a compiled language. In my previous blog I have explained how a C program works, Today I will show you how we can compile our c program. So there are many methods for compiling the program. But first, let me tell you about the C compiler.

C Compiler:

The compiler of C is known as GCC (GNU Compiler Collection), which is not only the C compiler it is the collection of the compilers of many languages like C, C++, Objective-C, Objective-C++, Fortran, Java, Ada, and Go, etc. We can compile any program of these languages with the help of the GCC. For example, we use 'gcc' for compiling C programs and 'g++' for compiling C++ programs.


Types of compilation:

It is very easy to compile and run a C program using any IDE like Turbo C, Dev C, etc. But if you do not have any IDE you can still compile and run your C program all you need is GCC Compiler. You can download it easily.

Compiling in Turbo C:

This video tutorial will help you to compile and run your C program.


Compiling without IDE:

Now it is important. Many interviewers can ask you this thing- "How to compile a C program without any IDE" or "How To compiler a program directly from Command line".
For compiling the program you want you should have to open Command Prompt/CMD/Command line/ Terminal anything you want. You must be in the directory where you have saved your program file. For example, I've saved a program file named "prog1.c" in "C:\Programs\" directory, then your current directory in command prompt should be the same(i.e. "C:\Programs\").

Syntax

C:\> gcc 'source_file.c' -o 'output_filename'
  • source file is your program file.
  • output file is your execution program file with '.exe' extension, You can write any name you want.

Step 1

Open Command prompt in Windows or Terminal in Linux.
Go to the working directory:

C:\>cd "C:\Programs\"
C:\Programs\>

Step 2

C:\Programs\>gcc prog1.c -o prog1
C:\Programs\>

A 'prog1.exe' file will appear in the same directory. Now we are ready to run that file.

Step 3

C:\Programs\>prog1.exe

This command will run your program and output will appear on the screen in command prompt.

Let me tell you something,
All IDEs use these commands for compiling and running the programs in the backend.
I hope you've learned something today. I'll be back again with another topic until then Happy Coding..!!

Comments

Popular posts from this blog

Conditional Statements and Conditional Operator | C Weekly

C Weekly | Data Types In C | Variables | Comments | Simple Program

Fundamentals of C | feel_the_coder | C Weekly