Open In App

C Language Introduction

Last Updated : 08 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

C is a general-purpose procedural programming language initially developed by Dennis Ritchie in 1972 at Bell Laboratories of AT&T Labs. It was mainly created as a system programming language to write the UNIX operating system.

Features-Of-C-language

Main features of C

Why Learn C?

C is considered mother of all programming languages as many later languages have borrowed syntax/features directly or indirectly from the C language like the syntax of Java, PHP, JavaScript, and many other languages that are mainly based on the C language.

So, if a person learns C programming first, it will help them to learn any modern programming language as well provide a deeper understanding of the fundamentals of programming and underlying architecture of the operating system like pointers, working with memory locations etc.

Writing First Program in C Language

This simple program demonstrates the basic structure of a C program. It will also help us understand the basic syntax of a C program.

C
#include <stdio.h>
int main(void)
{
    // This prints "Hello World"
    printf("Hello World");
    return 0;  
}

Output
Hello World

Let us analyse the structure of our program line by line.

Structure of the C program

After the above discussion, we can formally assess the basic structure of a C program. By structure, it is meant that any program can be written in this structure only. Writing a C program in any other structure will lead to a Compilation Error. The structure of a C program is as follows:

structure-of-c-program

Header Files Inclusion – Line 1 [#include <stdio.h>]

The first component is the Header files in a C program. A header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source files. All lines that start with # are processed by a preprocessor which is a program invoked by the compiler. In the above example, the preprocessor copies the preprocesses code of stdio.h to our file. The .h files are called header files in C.
Some of the C Header files:

  • stddef.h – Defines several useful types and macros.
  • stdint.h – Defines exact width integer types.
  • stdio.h – Defines core input and output functions
  • stdlib.h – Defines numeric conversion functions, pseudo-random number generator, and memory allocation
  • string.h – Defines string handling functions
  • math.h – Defines common mathematical functions.

Main Method Declaration – Line 2 [int main()]

The next part of a C program is the main() function. It is the entry point of a C program and the execution typically begins with the first line of the main(). The empty brackets indicate that the main doesn’t take any parameter (See this for more details). The int that was written before the main indicates the return type of main(). The value returned by the main indicates the status of program termination.

Body of Main Method – Line 3 to Line 6 [enclosed in {}]

The body of the main method in the C program refers to statements that are a part of the main function. It can be anything like manipulations, searching, sorting, printing, etc. A pair of curly brackets define the body of a function. All functions must start and end with curly brackets.

Comment – Line 7[// This prints “Hello World”]

The comments are used for the documentation of the code or to add notes in your program that are ignored by the compiler and are not the part of executable program .

Statement – Line 4 [printf(“Hello World”);]

Statements are the instructions given to the compiler. In C, a statement is always terminated by a semicolon (;). In this particular case, we use printf() function to instruct the compiler to display “Hello World” text on the screen.

Return Statement – Line 5 [return 0;]

The last part of any C function is the return statement. The return statement refers to the return values from a function. This return statement and return value depend upon the return type of the function. The return statement in our program returns the value from main(). The returned value may be used by an operating system to know the termination status of your program. The value 0 typically means successful termination. 

Execute C Programs

In order to execute the above program, we need to first compile it using a compiler and then we can run the generated executable. There are online IDEs available for free like GeeksforGeeksIDE, that can be used to start development in C without installing a compiler.

  1. Windows: There are many free IDEs available for developing programs in C like Code Blocks and Dev-CPP. IDEs provide us with an environment to develop code, compile it and finally execute it. We strongly recommend Code Blocks.
  2. Linux: GCC compiler comes bundled with Linux which compiles C programs and generates executables for us to run. Code Blocks can also be used with Linux. 
  3. macOS: macOS already has a built-in text editor where you can just simply write the code and save it with a “.c” extension.

Difference Between C and C++

C++ was created to add the OOPs concept into the C language so they both have very similar syntax with a few differences. The following are some of the main differences between C and C++ Programming languages.

Feature

C

C++

Paradigm

Procedural programming

Procedural, Object-Oriented, Generic

OOPs

Not Supported

Supports OOPs concepts with classes, inheritance, polymorphism, and encapsulation.

Memory Management

Manual using malloc(), calloc(), free() etc.

Both Manual and Automatic (using new, delete for dynamic allocation and deallocation)

Function Overloading

Not Supported ( function names must be unique. )

Supports function overloading.

Operator Overloading

Not Supported ( every operator performs unique operation. )

Supports operator overloading, allows custom behaviors for operators like +, -, *, etc.

Access Control

Doesn’t have any access control mechanism.

Supports access control using keywords like private, public , protected.

Application of C Language

C language is being used since the early days of computer programming and still is used in wide variety of applications such as:

  • C is used to develop core components of operating systems such as Windows, Linux, and macOS.
  • C is applied to program embedded systems in small devices such as washing machines, microwave ovens, and printers.
  • C is utilized to create efficient and quick game engines. For example, the Doom video game engine was implemented using C.
  • C is employed to construct compilers, assemblers, and interpreters. For example, the CPython interpreter is written partially using C.
  • C is applied to develop efficient database engines. The MySQL database software is implemented using C and C++.
  • C is employed to create programs for devices and sensors of Internet of Things (IoT). A common example is a house automation system comprising temperature sensors and controllers that is often prepared with C.
  • C is employed for creating lightweight and speedy desktop applications. The widely used text editor Notepad++ employs C for performance-sensitive sections.


Next Article
Article Tags :

Similar Reads

  翻译: