Get Started Programming Using C

The C Compiler allows the computer to turn the human readable source code into machine language that your program can read. The process is called compiling. The most commonly used and free compiler is GNU C/C++ which works on various operating systems, called GCC. Note: The compiler will also work with C++ programs in addition to C.

C_Programming_Logo.png

Installation on UNIX/Linux

If you are using Linux or UNIX, you can start by checking if GCC, the most popular C compiler, is installed on your system by typing the following command in terminal:

gcc -v

If you have GCC installed on your system, then you should see a message that looks something like this:

Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr .......
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)

If GCC is not installed, you can install it yourself by going to http://gcc.gnu.org/install/. Full instructions are available from that webpage.

Install on Mac OS X

If you use Mac OS X the easiest way to install GCC is to install the Xcode development environment available from the Mac App Store for free. Once you install Xcode, you will be able to use GCC for compiling in C.

Install on Windows

If you are using Windows you need to install MinGW from here. Download the latest version which should be named MinGW-<version>.exe. While installing MinGW, at a minimum you must install gcc-core, gcc-g++, binutils, and the MinGW runtime.

Then, add the bin subdirectory of your MinGW installation to your PATH environment variable, which makes it easier to specify these tools on the command line by their simple names.

After the installation is complete, you will be able to run gcc and several other tools from Command Prompt on Windows.

Writing Your First Program

The source code of your program can be written in any text editor like Notepad, EMACS, VIM, VI, and many more. The text editor will be different depending on your operating system.

The file you create with your text editor, called the source code of your program, must be saved with a ".c" extension. When you save your program, open terminal or command prompt, navigate to the directory that your ".c" file is stored.

Try the following example as your first program.

#include <stdio.h>

int main()
{
 printf("Hello, World! \n");
 
 return 0;
}

Copy and paste the following into a blank ".c" file and save the file. Navigate to the file in terminal and type "gcc <filename>.c" and hit enter. Your program is now compiled. To run your program and see the output type "./a.out". The output will be displayed in your current terminal/command prompt window.

Square Partners With Griffin to Create Case and Card Reader at CES 2014

FISA Court Allows NSA to Collect Call Metadata (again)