Close
Close

Learn C : Introduction


C is one of the most widely used computer programming languages. The reason C is so popular is because it is reliable, simple and easy to use. This is why despite the fact that so many new languages have come up, C continues to be the most widely used.

Why should we learn C ?


Features of C

  • C is fast
  • Easy to learn
  • Most powerful programming language
  • Has many built-in functions and operators which can make complex programs easy
  • Can be compiled on a number of computer platforms
  • Fast and efficient
  • Programs written in C are portable i.e., programs written for one type of computer or operating system can run on another type of computer or operating system with minimal modifications.
  • Also largely used in many large-scale projects

How to start ?

In this whole C tutorial, we will be learning about writing C programs. But what after that?

After writing any program, we need to compile and run it to see the output of the program.

So, what is meant by compiling ?

When we write our program in C language, it needs to be converted to machine language (which is binary language consisting of 0s and 1s) so that computer can understand and execute it. This conversion is known as compiling a program. We compile a code with the help of a compiler.

Integrated Development Environment (IDE)

To write and compile our C program, we have been provided with many IDEs.

An IDE consists of a Text Editor as well as the Compiler. We type our program in the text editor which will then be compiled by the compiler.

Text Editor


We write our program in a text editor. The file containing our program is called source file and is saved with .c extension.

C Compiler


After saving our program in a file with the .c extension, we need to compile it. As we have seen, we need to compile our code to convert it into machine language that computer can understand.

Now let's see how to compile and execute a C program on different operating systems.

Writing and compiling C program on Windows


Though there are many IDEs are available for editing and compiling C programs for Windows, here we are talking about editing and compiling program using DevC++ which allows us to edit, compile and run our program. We can write and save our program using DevC++ itself and then compile it using the same.

Before learning to write a program in Devc++, first make sure it is installed in your computer. If not, then download and install it.

To write and compile in DevC++, follow the steps below.

1. On opening DevC++, you will get a window. Click on 'source file' option.

opening file in devc++

2. Write your C program in the white space as shown below and save it.

#include <stdio.h>
int main()
{
    printf("Hello World\n");
    return 0;
}

writing on file in devc++

writing on file in devc++

3. Once you have written the program, click on compile and run.

compiling C file in devc++

4. An output window will appear, showing the result that is "Hello World" printed.

Run C file in devc++

Now, you are ready to go for next chapter. We will explain this code in the next chapter.

Writing and compiling C program on Linux


For Linux, you can write your C program in various text editors like vim, gedit or Emacs. The following steps show how to edit and compile your C program, assuming that the text editor is gedit.

1. Open Terminal ( ctrl+alt+T ).

2. Open a new file with .c extension (in our case name of the file is hello.c) in your favourite editor (in our case, gedit). The command is :

gedit hello.c

open file with .c in gedit

3. The text editor window will be opened. Type the below C program below (we will explain this code in the next chapter) and save it.

#include <stdio.h>
int main()
{
    printf("Hello World\n");
    return 0;
}

4. To compile the program, type cc -c hello.c (i.e., cc -c filename) and press Enter.

compile c file in terminal

5. Now type cc hello.c -o hello and press Enter. This will create executable file with name hello (you can give any other name also but you will execute the file with that name only).

create executable c file in terminal

6. To run your program, type ./hello (hello is the name of the executable file we created in step 5) and press Enter. This will show the output of your program.

run c file in terminal

So, you can see "Hello World" printed on your screen. Now, you know how to write and compile C codes. So, you can go to next chapter to understand this code.

To learn from simple videos, you can always look at our C++ video course on CodesDope Pro. It has over 750 practice questions and over 200 solved examples.


Ask Yours
Post Yours
Doubt? Ask question