C - Environment Setup
C - Environment Setup
C - Environment Setup
To start learning programming in C, the first step is to setup an environment that
allows you to enter and edit the program in C, and a compiler that builds an
executable that can run on your operating system. You need two software tools
available on your computer, (a) The C Compiler and (b) Text Editor.
The C Compiler
The source code written in the source file is the human readable source for your
program. It needs to be "compiled", into machine language so that your CPU can
actually execute the program as per the instructions given.
There are many C compilers available. Following is a select list of C compilers that
are widely used −
The examples in this tutorial are compiled on the GCC compiler. The most frequently
used and free available compiler is the GNU C/C++ compiler. The following section
explains how to install GNU C/C++ compiler on various operating systems. We keep
mentioning C/C++ together because GNU gcc compiler works for both C and C++
programming languages.
Installation on UNIX/Linux
If you are using Linux or UNIX, then check whether GCC is installed on your system
by entering the following command from the command line −
https://www.tutorialspoint.com/cprogramming/c_environment_setup.htm 1/4
6/16/24, 10:55 AM C - Environment Setup
$ gcc -v
If you have GNU compiler installed on your Ubuntu Linux machine, then it should
print a message as follows −
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v . . .
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04)
If GCC is not installed, then you will have to install it yourself using the detailed
instructions available at https://gcc.gnu.org/install/
Installation on Mac OS
If you use Mac OS X, the easiest way to obtain GCC is to download the Xcode
development environment from Apple's web site and follow the simple installation
instructions. Once you have Xcode setup, you will be able to use GNU compiler for
C/C++.
Installation on Windows
To install GCC on Windows, you need to install MinGW. To install MinGW, go to the
MinGW downloads page, https://www.mingw-w64.org/downloads/, and follow the
link to the MinGW download page. Download the latest version of the MinGW
installation program, mingw-w64-install.exe from here.
While installing Min GW, at a minimum, you must install gcc-core, gcc-g++, binutils,
and the MinGW runtime, but you may wish to install more.
Add the bin subdirectory of your MinGW installation to your PATH environment
variable, so that you can specify these tools on the command line by their simple
names.
https://www.tutorialspoint.com/cprogramming/c_environment_setup.htm 2/4
6/16/24, 10:55 AM C - Environment Setup
After the installation is complete, you will be able to run gcc, g++, ar, ranlib, dlltool,
and several other GNU tools from the Windows command line.
Text Editor
You will need a Text Editor to type your program. Examples include Windows
Notepad, OS Edit command, Brief, Epsilon, EMACS, and vim or vi.
The name and version of the text editors can vary on different operating systems.
For example, Notepad will be used on Windows, and vim or vi can be used on
windows as well as on Linux or UNIX.
The files you create with your editor are called the source files and they contain the
program source codes. The source files for C programs are typically named with the
extension ".c".
Before starting your programming, make sure you have one text editor in place and
you have enough experience to write a computer program, save it in a file, compile it
and finally execute it.
Using an IDE
Using a general-purpose text editor such as Notepad or vi for program development
can be very tedious. You need to enter and save the program with ".c" extension
(say "hello.c"), and then compile it with the following command −
The executable file is then run from the command prompt to obtain the output.
However, if the source code contains errors, the compilation will not be successful.
Hence we need to repeatedly switch between the editor program and command
terminal. To avoid this tedious process, we should an IDE (Integrated Development
Environment).
There are many IDEs available for writing, editing, debugging and executing C
programs. Examples are CodeBlocks, NetBeans, VSCode, etc.
https://www.tutorialspoint.com/cprogramming/c_environment_setup.htm 3/4
6/16/24, 10:55 AM C - Environment Setup
well as MinGW compiler on your computer. During the installation process, choose
MinGW as the compiler to use.
Example
After the installation is complete, launch it and enter the following code −
#include <stdio.h>
int main() {
/* my first program in C */
printf("Hello, World! \n");
return 0;
}
Output
Hello, World!
From the Build menu, build and run the program (use F9 shortcut). The Build Log
window shows successful compilation messages. The output (Hello World) is
displayed in a separate command prompt terminal.
https://www.tutorialspoint.com/cprogramming/c_environment_setup.htm 4/4