Application of C
Operating systems: C is widely used for developing operating systems such as Unix, Linux,
and Windows.
Embedded systems: C is a popular language for developing embedded systems such as
microcontrollers, microprocessors, and other electronic devices.
System software: C is used for developing system software such as device drivers, compilers,
and assemblers.
Networking: C is widely used for developing networking applications such as web servers,
network protocols, and network drivers.
Database systems: C is used for developing database systems such as Oracle, MySQL, and
PostgreSQL.
Gaming: C is often used for developing computer games due to its ability to handle low-level
hardware interactions.
Artificial Intelligence: C is used for developing artificial intelligence and machine learning
applications such as neural networks and deep learning algorithms.
Scientific applications: C is used for developing scientific applications such as simulation
software and numerical analysis tools.
Financial applications: C is used for developing financial applications such as stock market
analysis and trading systems.
Features of C Programming Language
C is a procedural programming language. It was initially developed by Dennis Ritchie in the
year 1972. It was mainly developed as a system programming language to write an operating
system.
The main features of C language include low-level access to memory, a simple set of
keywords, and a clean style, these features make C language suitable for system
programming like an operating system or compiler development.
What are the Most Important Features of C Language?
Here are some of the most important features of the C language:
Procedural Language
Fast and Efficient
Modularity
Statically Type
General-Purpose Language
Rich set of built-in Operators
Libraries with Rich Functions
Middle-Level Language
Portability
Easy to Extend
1. Procedural Language
In a procedural language like C step by step, predefined instructions are carried out. C program may
contain more than one function to perform a particular task. New people to programming will think
that this is the only way a particular programming language works. There are other programming
paradigms as well in the programming world. Most of the commonly used paradigm is an object-
oriented programming language.
2. Fast and Efficient
Newer languages like Java, python offer more features than c programming language but due to
additional processing in these languages, their performance rate gets down effectively. C
programming language as the middle-level language provides programmers access to direct
manipulation with the computer hardware but higher-level languages do not allow this. That’s one of
the reasons C languages is considered the first choice to start learning programming languages. It’s
fast because statically typed languages are faster than dynamically typed languages.
3. Modularity
The concept of storing C programming language code in the form of libraries for further future uses
is known as modularity. This programming language can do very little on its own most of its power is
held by its libraries. C language has its own library to solve common problems.
4. Statically Type
C programming language is a statically typed language. Meaning the type of variable is checked at
the time of compilation but not at run time. This means each time a programmer types a program
they have to mention the type of variables used.
5. General-Purpose Language
From system programming to photo editing software, the C programming language is used in various
applications. Some of the common applications where it’s used are as follows:
Operating systems: Windows, Linux, iOS, Android, OXS
Databases: PostgreSQL, Oracle, MySQL, MS SQL Server, etc.
6. Rich set of built-in Operators
It is a diversified language with a rich set of built-in operators which are used in writing complex or
simplified C programs.
7. Libraries with Rich Functions
Robust libraries and functions in C help even a beginner coder to code with ease.
8. Middle-Level Language
As it is a middle-level language so it has the combined form of both capabilities of assembly language
and features of the high-level language.
9. Portability
C language is lavishly portable as programs that are written in C language can run and compile on any
system with either no or small changes.
10. Easy to Extend
Programs written in C language can be extended means when a program is already written in it then
some more features and operations can be added to it.
C Programming Language Standard
Introduction:
The C programming language has several standard versions, with the most commonly used ones
being C89/C90, C99, C11, and C18.
1. C89/C90 (ANSI C or ISO C) was the first standardized version of the language, released in
1989 and 1990, respectively. This standard introduced many of the features that are still used
in modern C programming, including data types, control structures, and the standard library.
2. C99 (ISO/IEC 9899:1999) introduced several new features, including variable-length arrays,
flexible array members, complex numbers, inline functions, and designated initializers. This
standard also includes several new library functions and updates to existing ones.
3. C11 (ISO/IEC 9899:2011) introduced several new features, including _Generic, static assert,
and the atomic type qualifier. This standard also includes several updates to the library,
including new functions for math, threads, and memory manipulation.
4. C18 (ISO/IEC 9899:2018) includes updates and clarifications to the language specification and
the library.
5. C23 standard (ISO/IEC 9899:2023) is the latest revision and include better support for the
const qualifier, new and updated library functions, and further optimizations for compiler
implementations.
When writing C code, it’s important to know which standard version is being used and to write code
that is compatible with that standard. Many compilers support multiple standard versions, and it’s
often possible to specify which version to use with a compiler flag or directive.
Here are some advantages and disadvantages of using the C programming language:
Advantages:
1. Efficiency: C is a fast and efficient language that can be used to create high-performance
applications.
2. Portability: C programs can be compiled and run on a wide range of platforms and operating
systems.
3. Low-level access: C provides low-level access to system resources, making it ideal for systems
programming and developing operating systems.
4. Large user community: C has a large and active user community, which means there are
many resources and libraries available for developers.
5. Widely used: C is a widely used language, and many modern programming languages are
built on top of it.
Disadvantages:
1. Steep learning curve: C can be difficult to learn, especially for beginners, due to its complex
syntax and low-level access to system resources.
2. Lack of memory management: C does not provide automatic memory management, which
can lead to memory leaks and other memory-related bugs if not handled properly.
3. No built-in support for object-oriented programming: C does not provide built-in support for
object-oriented programming, making it more difficult to write object-oriented code
compared to languages like Java or Python.
4. No built-in support for concurrency: C does not provide built-in support for concurrency,
making it more difficult to write multithreaded applications compared to languages like Java
or Go.
5. Security vulnerabilities: C programs are prone to security vulnerabilities, such as buffer
overflows, if not written carefully.
Overall, C is a powerful language with many advantages, but it also requires a high degree of
expertise to use effectively and has some potential drawbacks, especially for beginners or
developers working on complex projects.
Importance:
important for several reasons:
1. Choosing the right programming language: Knowing the advantages and disadvantages of C
can help developers choose the right programming language for their projects. For example,
if high performance is a priority, C may be a good choice, but if ease of use or built-in
memory management is important, another language may be a better fit.
2. Writing efficient code: Understanding the efficiency advantages of C can help developers
write more efficient and optimized code, which is especially important for systems
programming and other performance-critical applications.
3. Avoiding common pitfalls: Understanding the potential disadvantages of C, such as memory
management issues or security vulnerabilities, can help developers avoid common pitfalls
and write safer, more secure code.
4. Collaboration and communication: Knowing the advantages and disadvantages of C can also
help developers communicate and collaborate effectively with others on their team or in the
wider programming community.
The idea of this article is to introduce C standard.
What to do when a C program produces different results in two different
compilers?
For example, consider the following simple C program.
void main () {}
The above program fails in GCC as the return type of main is void, but it compiles in Turbo C. How do
we decide whether it is a legitimate C program or not?
Consider the following program as another example. It produces different results in different
compilers.
// C++ Program to illustrate the difference in different
// compiler execution
#include <stdio.h>
int main()
int i = 1;
printf("%d %d %d\n", i++, i++, i);
return 0;
2 1 3 - using g++ 4.2.1 on Linux.i686
1 2 3 - using SunStudio C++ 5.9 on Linux.i686
2 1 3 - using g++ 4.2.1 on SunOS.x86pc
1 2 3 - using SunStudio C++ 5.9 on SunOS.x86pc
1 2 3 - using g++ 4.2.1 on SunOS.sun4u
1 2 3 - using SunStudio C++ 5.9 on SunOS.sun4u
Source: Stackoverflow
Which compiler is right?
The answer to all such questions is C standard. In all such cases, we need to see what C standard says
about such programs.
What is C standard?
The latest C standard is ISO/IEC 9899:2018, also known as C17 as the final draft was published in
2018. Before C11, there was C99. The C11 final draft is available here. See this for a complete history
of C standards.
Can we know the behavior of all programs from C standard?
C standard leaves some behavior of many C constructs as undefined and some as unspecified to
simplify the specification and allow some flexibility in implementation. For example, in C the use of
any automatic variable before it has been initialized yields undefined behavior and order of
evaluations of subexpressions is unspecified. This specifically frees the compiler to do whatever is
easiest or most efficient, should such a program be submitted.
So what is the conclusion about above two examples?
Let us consider the first example which is “void main() {}”, the standard says following about
prototype of main().
The function called at program startup is named main. The implementation
declares no prototype for this function. It shall be defined with a return
type of int and with no parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names
may be used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent;10) or in some other implementation-defined manner.
So the return type void doesn’t follow the standard, and it’s something allowed by certain compilers.
Let us talk about the second example. Note the following statement in C standard is listed under
unspecified behavior.
The order in which the function designator, arguments, and
subexpressions within the arguments are evaluated in a function
call (6.5.2.2).
What to do with programs whose behavior is undefined or unspecified in standard?
As a programmer, it is never a good idea to use programming constructs whose behavior is undefined
or unspecified, such programs should always be discouraged. The output of such programs may
change with the compiler and/or machine.
C Hello World Program
The “Hello World” program is the first step towards learning any programming language. It is also
one of the simplest programs that is used to introduce aspiring programmers to the programming
language. It typically outputs the text “Hello, World!” to the console screen.
C Program to Print “Hello World”
To print the “Hello World”, we can use the printf function from the stdio.h library that prints the
given string on the screen. Provide the string “Hello World” to this function as shown in the below
code:
// Header file for input output functions
#include <stdio.h>
// Main function: entry point for execution
int main() {
// Writing print statement to print hello world
printf("Hello World");
return 0;
Output
Hello World
Explanation:
#include <stdio.h> – This line includes the standard input-output library in the program.
int main() – The main function where the execution of the program begins.
printf(“Hello, World!\n”); – This function call prints “Hello, World!” followed by a new line.
return 0; -This statement indicates that the program ended successfully.
To go beyond the basics and explore data structures and more advanced topics, the C Programming
Course Online with Data Structures takes you from beginner to expert
Master C with our C Programming online course! From basics to advanced topics like data
structures, enhance your skills with hands-on coding challenges. Take the Three 90 Challenge—
complete 90% in 90 days, and earn a 90% refund. Start your learning journey today!
Compiling a C Program: Behind the Scenes
Last Updated : 10 Jan, 2025
The compilation is the process of converting the source code of the C language into machine code. As
C is a mid-level language, it needs a compiler to convert it into an executable code so that the
program can be run on our machine.
The C program goes through the following phases during compilation:
Compilation Process in C
Understanding the compilation process in C helps developers optimize their programs.
How do we compile and run a C program?
We first need a compiler and a code editor to compile and run a C Program. The below example is of
an Ubuntu machine with GCC compiler.
Step 1: Creating a C Source File
We first create a C program using an editor and save the file as filename.c
$ vi filename.c
We can write a simple hello world program and save it.
Step 2: Compiling using GCC compiler
We use the following command in the terminal for compiling our filename.c source file
$ gcc filename.c –o filename
We can pass many instructions to the GCC compiler to different tasks such as:
The option -Wall enables all compiler’s warning messages. This option is recommended to
generate better code.
The option -o is used to specify the output file name. If we do not use this option, then an
output file with the name a.out is generated.
If there are no errors in our C program, the executable file of the C program will be generated.
Step 3: Executing the program
After compilation executable is generated and we run the generated executable using the below
command.
$ ./filename
The program will be executed and the output will be shown in the terminal.
What goes inside the compilation process?
A compiler converts a C program into an executable. There are four phases for a C program to
become an executable:
1. Pre-processing
2. Compilation
3. Assembly
4. Linking
By executing the below command, we get all intermediate files in the current directory along with
the executable.
$gcc -Wall -save-temps filename.c –o filename
The following screenshot shows all generated intermediate files.
Intermediate Files
Let us one by one see what these intermediate files contain.
1. Pre-processing
This is the first phase through which source code is passed. This phase includes:
Removal of Comments
Expansion of Macros
Expansion of the included files.
Conditional compilation
The preprocessed output is stored in the filename.i. Let’s see what’s inside filename.i: using $vi
filename.i
In the above output, the source file is filled with lots and lots of info, but in the end, our code is
preserved.
printf contains now a + b rather than add(a, b) that’s because macros have expanded.
Comments are stripped off.
#include<stdio.h> is missing instead we see lots of code. So header files have been expanded
and included in our source file.
2. Compiling
The next step is to compile filename.i and produce an; intermediate compiled output file filename.s.
This file is in assembly-level instructions. Let’s see through this file using $nano filename.s terminal
command.
Assembly Code File
The snapshot shows that it is in assembly language, which the assembler can understand.
3. Assembling
In this phase the filename.s is taken as input and turned into filename.o by the assembler. This file
contains machine-level instructions. At this phase, only existing code is converted into machine
language, and the function calls like printf() are not resolved. Let’s view this file using $vi filename.o
Binary Code
4. Linking
This is the final phase in which all the linking of function calls with their definitions is done. Linker
knows where all these functions are implemented. Linker does some extra work also, it adds some
extra code to our program which is required when the program starts and ends. For example, there is
a code that is required for setting up the environment like passing command line arguments. This
task can be easily verified by using $size filename.o and $size filename. Through these commands,
we know how the output file increases from an object file to an executable file. This is because of the
extra code that Linker adds to our program.