Programming Concepts
using C Language
TBD-204
[Link] Negi
UNIT-1
Introduction to Programming in C
• History of C, Structure of a C Program, printf(), scanf(), Hello World Program,
Format Specifiers, Single Character input/output, Formatted input/output
Functions, commenting and documentation, indentation and formatting
guidelines,
• Constants and variables: Types of Constants, Keywords, Rules for identifiers,
The character set,
• Built-in data types: int, float, char, double, long, void
• Operators: Arithmetic Operators, Increment and Decrement Operators,
Relational Operators, Logical Operators, Bitwise Operators, Conditional
Operators, Type Conversions, and expressions, Precedence, and associativity of
operators
HISTORY OF C LANGUAGE
1. The C language was created and developed by Dennis Ritchie and Ken
Thompson in 1972 at Bell Labs, AT&T (American Telephone & Telegraph),
located in the United States of America.
2. But before that , programming languages is ALGOL (i.e., Algorithmic
Language), and it was the first programming language developed in the
1960s.
3. Later on, the Basic Combined Programming Language (BCPL) was
developed by Martin Richards in 1967, and BCPL was the programming
language derived from ALGOL.
4. In the year 1970, the B language originated from BCPL and was created
by Ken Thompson, and both these programming languages were typeless.
5. In 1972, the C programming language was developed to overcome the
problems of previous languages, such as B, BCPL, etc. Initially, it was
mainly utilized for rewriting and developing the UNIX operating system,
which makes it portable and robust.
• The widespread adoption of C began with the publication of "The C
Programming Language" by Brian Kernighan and Dennis Ritchie
(K&R) in 1978. This book served as the informal specification for the
language for many years, defining what became known as "K&R C."
• The need for a formal, standardized definition of C became apparent
as different compilers introduced their own extensions. The American
National Standards Institute (ANSI) formed a committee in 1983 to
standardize C, resulting in ANSI C (C89) in 1989. This standard was
subsequently adopted by the International Organization for
Standardization (ISO) as C90.
• Subsequent revisions to the C standard have introduced new features
and clarified existing ones, while striving for backward compatibility:
Language Year Developed By
Algol 1960 International Group
BCPL 1967 Martin Richard
B 1970 Ken Thompson
Traditional C 1972 Dennis Ritchie
K&RC 1978 Kernighan & Dennis Ritchie
ANSI C 1989 ANSI Committee
ANSI/ISO C 1990 ISO Committee
C99 1999 Standardization Committee
C11 2011 ISO Committee
C17/C18 2018 ISO Committee
C23 2024 ISO Committee
Versions of the C programming
language-
1. K & R C (1978)
In 1978, Brian Kernighan and Dennis Ritchie launched the first edition of
their book named as "The C Programming Language". It was mainly known
as the "K&R" book. It served as the first standardized and popularized C
worldwide.
2. ANSI C (1989)
In the 1980s, ANSI, the American National Standards Institute (ANSI), started
working on the formal standard for the C language. It helps to develop ANSI
C very effectively, which was standardized (C89) in 1989. It came with several
essential features, such as function prototypes, a standard library, better
type checking, and a standardized preprocessor. It resolved all the issues
that were present in the earlier versions of the C language.
3. ANSI/ISO C (1990)
In the 1990s, the ANSI C standard was approved by the International
Organization for Standardization (ISO) as C90 (ISO/IEC 9899:1990). It
was commonly utilized as the basis for compilers and development for
many years. It came with several new features, such as syntax,
semantics, libraries, and many more. From then on, every new version
of the C programming language was released jointly by the ANSI and
ISO.
4. C99 (1999)
In the year 1999, the C programming language introduced a new
version named C99. It came with several features, including variable-
length arrays, inline functions, complex numbers, and many more. It
also included the long long data type and the single-line comments (//).
5. C11 (2011)
In the year 2011, C introduced a new version of the C standard programming language, that is
published by the International Organization for Standardization (ISO), named C11. It included several
new features, libraries, and ensured safety and concurrency. It introduced several new features, such
as anonymous structure and unions, multi-threading support, Generic type-generic programming,
and Unicode support.
6. C17/C18 (2018)
In the year 2018, the C programming language released a new version of C named C17/C18. It is a
minor updated version of C11. The ISO published it as C18, while some publishers and compilers call
it C17. It resolved all the previous issues that came in the C11. It came with some new additional
features, such as threading, atomics, bound-checking interfaces, and many others.
7. C23 (2023)
In the year 2023, the C programming language introduced a new version of C named C23. It is the
latest version of the C programming language. It was published by the ISO in 2024 as ISO/IEC
9899:2024. It is an upgraded version of C17/C18. It includes several important features, such as
binary literals, nullptr, static assertions, and many others. It introduced 14 new keywords in C. C23
supports modern hardware architecture.
Features of the C Programming Language-
1. Simplicity and Efficiency-
C is a relatively small and simple language compared to many other
programming languages. It has a concise set of keywords and a
straightforward syntax, making it easier to learn and understand.
Despite its simplicity, C is highly efficient. It provides low-level memory
access through pointers, allowing programmers to write highly
optimized code that runs very fast.
2. Portability
C programs are highly portable. This means that C code written on one
type of computer system (e.g., a Windows PC) can often be compiled
and run on another system (e.g., a Linux server or an embedded
system) with little or no modification. This is because C compilers are
available for almost all hardware platforms and operating systems.
3. Mid-level Language-
C is often referred to as a mid-level programming language. It
combines the features of both high-level languages (like structured
programming and data types) and low-level languages (like direct
memory manipulation). This allows C to be used for both system-level
programming (like operating systems and embedded systems) and
application-level programming.
4. Structured Programming Language-
C is a structured programming language. It supports the use of
functions, loops (for, while, do-while), and conditional statements (if-
else, switch-case), which allow programmers to write modular,
organized, and readable code. This approach helps in breaking down
complex problems into smaller, manageable functions.
5. Rich Set of Libraries-
C comes with a rich set of built-in functions and libraries that provide a
wide range of functionalities. The standard C library (libc) includes
functions for input/output operations (stdio.h), string manipulation
(string.h), mathematical calculations (math.h), memory management
(stdlib.h), and more. These libraries significantly reduce the amount of
code a programmer needs to write from scratch.
6. Memory Management-
C offers direct memory management capabilities through the use of
pointers. Programmers can explicitly allocate and deallocate memory
using functions like malloc(), calloc(), realloc(), and free(). This low-level
control over memory allows for efficient resource utilization and is
crucial for system programming.
7. Pointers-
Pointers are a powerful and integral feature of C. They are variables
that store memory addresses. Pointers enable direct memory access,
dynamic memory allocation, efficient array and string manipulation,
and the creation of complex data structures like linked lists and trees.
While powerful, they also require careful handling to avoid common
programming errors.
8. Recursion-
C supports recursion, which is the ability of a function to call itself. This
allows for elegant solutions to problems that can be broken down into
smaller, self-similar sub-problems, such as tree traversals, factorial
calculations, and Fibonacci series generation.
9. Extensibility-
C is highly extensible. It can easily interact with assembly language code, allowing programmers to write
highly optimized routines for specific hardware. Furthermore, C programs can be linked with libraries
written in other languages. [9]
10. Case-Sensitive-
C is a case-sensitive language. This means that myVariable, myvariable, and MYVARIABLE are treated as
three different identifiers by the C compiler. [10]
11. Compiler-Based-
C is a compiled language. C source code is translated into machine code by a compiler before execution.
This compilation process results in fast execution speeds, as the program is directly executed by the CPU
without the need for an interpreter at runtime. [11]
12. Modularity-
C promotes modularity through the use of functions and separate compilation. Large programs can be
broken down into multiple source files, each containing related functions. These files can be compiled
independently and then linked together to form the final executable, which speeds up compilation times
for large projects.
Applications of the C
Programming Language-
1. There are several applications of the C programming language. Some
of them are as follows:
2. The C programming language is commonly utilized to develop and
create embedded systems, system applications, desktop applications,
and many others.
3. It is also utilized for the Internet of Things (IoT).
4. The C programming language is very useful for developing browsers
and several extensions.
5. It is also useful in Adobe applications.
6. We can use the C programming language to create databases.