Compile and Execute the C Program

There are numerous compilers and text editors we can use to compile and execute the C program. These compilers and text editors may differ from system to system.

Run C Program Online

There are several sites that allow us to run C programming online. But online compilers have some limitations. We can’t work with files. Taking input from the user is very common in programming but many times using online compilers we can’t take input from the user. These are some top websites to run C program online.

  • Ideone:- This is a very simple compiler for small projects. It’s good for checking small snippets.
  • onlinegdb:- It is simple, and has a better debugger for C and C++ than you’d find on a terminal. It allows you to create an account and save your projects.
  • codepad:- This compiler is mostly used in interviews because it allows you to connect with other people. The free versions are simply the compiler/IDE, however. You’re likely to use this one or one like it if you’re ever in a coding interview.
  • codechef:- This one, too, is good for small snippets, but it allows you to open several tabs of code.
  • code.hackerearth.com
  • jdoodle.com

Compile and execute the C program in Windows

To run C Programming in Windows, download an IDE called Code:: Blocks. IDE is a piece of software that provides useful features like code hinting, syntax highlighting and checking, file explorers, etc. to the programmer for application development. Code Blocks is an IDE for edit, compile and run C/C++.

Visit the official page of Code Block or download codeblocks-<version>-mingw-setup.exe directly from Sourceforge.

Run C program on Linux

IDE (Code Blocks) is also available for Linux but it is not the best way to write programs in Linux. Code Blocks can be used because of Debug features of Code Block really cool. In Ubuntu, we can install the GCC compiler to compile and run C/C++.

Download Code Block for Linux,

To download Code Blocks issue the following command in the terminal,

$ sudo add-apt-repository ppa:damien-moore/codeblocks-stable
$ sudo apt-get update
$ sudo apt-get install codeblocks codeblocks-stable

If you got a problem like “It seems that this project has not been built yet. Do you want to build it now?” And if you click yes then it just returns to the same dialogue until you choose “No”.
Solution:- $ sudo apt-get install build-essential

Download GCC Compiler for Linux,

To run a C program in Linux we need a text editor, a compiler, development tools, and libraries. Any text editor can be used vim, sublime text editor, or atom. For compiler, we will install the GNU GCC compiler which is good for beginners.

Open the terminal and issue the following command,

$ sudo apt-get update
$ sudo apt-get install gcc

This installs GNU GCC compiler and related tools on your system.

gcc in linux
Installing GCC Compiler on Linux(Ubuntu)

To verify if gcc compiler is installed, issue the command,

$ gcc --version
gcc version
Verify GCC version on Linux(Ubuntu)

Open the text editor of your choice and save a file with .c extension. Any editor is fine but, don’t forget to use .c extension; it’s important.

Using the terminal switch to the directory where the file is located. And, issue the following command for the build Purpose.

$ gcc program-source-code.c -o  name-of-your-choice

Here, program-source-code.c is the filename you have chosen before. And, name-of-your-choice can be any name you prefer. If there is no error, an executable file having name name-of-your-choice is created.

Finally, you can see the output using the following command,

$ ./name-of-your-choice

For example, if we saved a Hello.c in a folder. First, go through that folder, now compile it using $ gcc Hello.c -o Hello

Now run it using,
$ ./Hello

Easy Method

On the LINUX/UNIX operating system, we must create the program in a file whose name ends in “.c”, such as hello.c, then compile it with the command cc hello.c

If we haven’t botched anything, such as omitting a character or misspelling something, the compilation will proceed silently, and make an executable file called a.out.We can access a.out using the following command, ./a.out

It will print the output. With this method, we can’t set the name of the output file. This command always gives output as “a.out”.

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *