Category: 01. Tutorial

https://cdn3d.iconscout.com/3d/premium/thumb/online-video-tutorial-3d-icon-png-download-8746901.png

  • History of C Language

    C programming is a general-purpose, procedure-oriented programming language. It is both machine-independent and structured. C is a high-level programming language developed by Dennis Ritchie in the early 1970s. It is now one of the most popular and influential programming languages worldwide.

    C is popular for its simplicity, efficiency, and versatility. It has powerful features including low-level memory access, a rich set of operators, and a modular framework.

    Apart from its importance with respect to the evolution of computer programming technologies, the design of C language has a profound influence on most of the other programming languages that are in use today. The languages that are influenced by C include JavaPHPJavaScriptC#Python and many more. These languages have designed their syntax, control structures and other basic features from C.

    C supports different hardware and operating systems due to its portability. Generally, it is considered as a basic language and influenced many other computer languages. It is most widely used in academia and industry. C’s relevance and extensive acceptance make it crucial for prospective programmers.

    The history of the C programming language is quite fascinating and pivotal in the development of computer science and software engineering.

    Year wise development of programming is as follows −

    C Language History

    Overview of C Language History

    A brief overview of C language history is given below −

    Origin of C Programming

    ‘ALGOL’ was the foundation or progenitor of programming languages. It was first introduced in 1960. ‘ALGOL’ was widely used in European countries. The ALGOL had introduced the concept of structured programming to the developer community. The year 1967 marked the introduction of a novel computer programming language known as ‘BCPL’, an acronym for Basic Combined Programming Language. BCPL was designed by Martin Richards in the mid-1960s.

    Dennis Ritchie

    Dennis Ritchie created C at Bell Laboratories in the early 1970s. It developed from an older language named B that Ken Thompson created. The main purpose of C’s creation was to construct the Unix operating system, which was crucial in the advancement of contemporary computers. BCPL, B, and C all fit firmly in the traditional procedural family typified by Fortran and Algol 60. BCPL, B and C differ syntactically in many details, but broadly they are similar.

    Development of C Programming

    In 1971, Dennis Ritchie started working on C, and he and other Bell Labs developers kept improving it. The language is appropriate for both system programming and application development because it was made to be straightforward, effective, and portable.

    Standardization of C Programming

    Dennis Ritchie commenced development on C in 1971 and, in collaboration with other developers at Bell Labs, proceeded to refine it. The language was developed with portability, simplicity, and efficiency in mind, rendering it applicable to both application and system programming.

    History of C Versions After Traditional C

    K&R C

    Dennis Ritchie along with Brian Kernighan published the first edition of their book “The C Programming Language”. Popularly known as K&R (the initials of its authors), the book served for many years as an informal specification of the language. The version of C that it describes is commonly referred to as “K&R C”. It is also referred to as C78.

    Many of the features of C language introduced in K&R C are still the part of the language ratified as late as in 2018. In early versions of C, only functions that return types other than int must be declared if used before the function definition; functions used without prior declaration were presumed to return type int.

    C compilers by AT&T and other vendors supported several features added to the K&R C language. Although C started gaining popularity, there was a lack of uniformity in implementation. Therefore, it was felt that the language specifications must be standardized.

    ANSI C

    In the 1980s, the American National Standards Institute (ANSI) began working on a formal standard for the C language. This led to the development of ANSI C, which was standardized in 1989. ANSI C introduced several new features and clarified ambiguities present in earlier versions of the language.

    C89/C90

    The ANSI C standard was adopted internationally and became known as C89 (or C90, depending on the year of ratification). It served as the basis for compilers and development tools for many years.

    C99

    In 1999, the ISO/IEC approved an updated version of the C standard known as C99. The C standard was further revised in the late 1990s.

    C99 introduced new features, including inline functions, several new data types such as a complex type to represent complex numbers, and variable-length arrays etc. It also added support for C++ style one-line comments beginning with //.

    C11

    C11, published in 2011, is another major revision of the C standard. The C11 standard adds new features to C and the library and introduced features such as multi-threading support, anonymous structures and unions, and improved Unicode support.

    It includes type generic macros, anonymous structures, improved Unicode support, atomic operations, multi-threading, and bounds-checked functions. It has an improved compatibility with C++.

    C17

    The C17 standard has been published in June 2018. C17 is the current standard for the C programming language. No new features have been introduced with this standard revision. It only performs certain technical corrections, and clarifications to defects in C11.

    C18

    The most recent version of the C standard, C18, was published in 2018. It includes minor revisions and bug fixes compared to C11.

    C23

    C23 is the informal name for the next major C language standard revision, expected to be published in 2024. 14 new keywords are expected to be introduced in this revision.

    C has remained popular over time because to its simplicity, efficiency, and versatility. It has been used to create a diverse spectrum of software including operating systems, embedded systems, applications, and games. C’s syntax and semantics have also impacted different modern programming languages such as C++, Java, and Python.

  • Features of C Programming Language

    Dennis Ritchie and Ken Thompson developed the C programming language in 1972, primarily to re-implement the Unix kernel. Because of its features such as low-level memory access, portability and cross-platform nature etc., C is still extremely popular. Most of the features of C have found their way in many other programming languages.

    The development of C has proven to be a landmark step in the history of computing. Even though different programming languages and technologies dominate today in different application areas such as web development, mobile apps, device drivers and utilities, embedded systems, etc., the underlying technologies of all of them are inspired by the features of C language.

    The utility of any technology depends on its important features. The features also determine its area of application. In this chapter, we shall take an overview of some of the significant features of C language.

    C is a Procedural and Structured Language

    C is described as procedure-oriented and structured programming language. It is procedural because a C program is a series of instructions that explain the procedure of solving a given problem. It makes the development process easier.

    In C, the logic of a process can be expressed in a structured or modular form with the use of function calls. C is generally used as an introductory language to introduce programming to school students because of this feature.

    C is a General-Purpose Language

    The C language hasn’t been developed with a specific area of application as a target. From system programming to photo editing software, the C programming language is used in various applications.

    Some of the common applications of C programming include the development of Operating Systems, databases, device drivers, etc.

    C is a Fast Programming Language

    C is a compiler-based language which makes the compilation and execution of codes faster. The source code is translated into a hardware-specific machine code, which is easier for the CPU to execute, without any virtual machine, as some of the other languages like Java need.

    The fact that C is a statically typed language also makes it faster compared to dynamically typed languages. Being a compiler-based language, it is faster as compared to interpreter-based languages.

    C is Portable

    Another feature of the C language is its portability. C programs are machine-independent which means that you can compile and run the same code on various machines with none or some machine-specific changes.

    C programming provides the functionality of using a single code on multiple systems depending on the requirement.

    C is Extensible

    C is an extensible language. It means if a code is already written, you can add new features to it with a few alterations. Basically, it allows adding new features, functionalities, and operations to an existing C program.

    Standard Libraries in C

    Most of the C compilers are bundled with an extensive set of libraries with several built-in functions. It includes OS-specific utilities, string manipulation, mathematical functions, etc.

    Importantly, you can also create your user-defined functions and add them to the existing C libraries. The availability of such a vast scope of functions and operations allows a programmer to build a vast array of programs and applications using the C language.

    Pointers in C

    One of the unique features of C is its ability to manipulate the internal memory of the computer. With the use of pointers in C, you can directly interact with the memory.

    Pointers point to a specific location in the memory and interact directly with it. Using the C pointers, you can interact with external hardware devices, interrupts, etc.

    C is a Mid-Level Programming Language

    High-level languages have features such as the use of mnemonic keywords, user-defined identifiers, modularity etc. C programming language, on the other hand, provides a low-level access to the memory. This makes it a mid-level language.

    As a mid-level programming language, it provides the best of both worlds. For instance, C allows direct manipulation of hardware, which high-level programming languages do not offer.

    C Has a Rich Set of Built-in Operators

    C is perhaps the language with the most number of built-in operators which are used in writing complex or simplified C programs. In addition to the traditional arithmetic and comparison operators, its binary and pointer related operators are important when bit-level manipulations are required.

    Recursion in C

    C language provides the feature of recursion. Recursion means that you can create a function that can call itself multiple times until a given condition is true, just like the loops.

    Recursion in C programming provides the functionality of code reusability and backtracking.

    User-defined Data Types in C

    C has three basic data types in intfloat and char. However, C programming has the provision to define a data type of any combination of these three types, which makes it very powerful.

    In C, you can define structures and union types. You also have the feature of declaring enumerated data types.

    Preprocessor Directives in C

    In C, we have preprocessor directives such as #include#define, etc. They are not the language keywords. Preprocessor directives in C carry out some of the important roles such as importing functions from a library, defining and expanding the macros, etc.

    File Handling in C

    C language doesn’t directly manipulate files or streams. Handling file IO is not a part of the C language itself but instead is handled by libraries and their associated header files.

    File handling is generally implemented through high-level I/O which works through streams. C identifies stdin, stdout and stderr as standard input, output and error streams. These streams can be directed to a disk file to perform read/write operations.

    These are some of the important features of C language that make it one of the widely used and popular computer languages.

  • Overview

    C is a general−purpose, high−level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC PDP-11 computer in 1972.

    In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available description of C, now known as the K&R standard.

    The UNIX operating system, the C compiler, and essentially all UNIX application programs have been written in C. C has now become a widely used professional language for various reasons −

    • Easy to learn
    • Structured language
    • It produces efficient programs
    • It can handle low−level activities
    • It can be compiled on a variety of computer platforms

    Facts about C

    • C was invented to write an operating system called UNIX.
    • C is a successor of B language which was introduced around the early 1970s.
    • The language was formalized in 1988 by the American National Standard Institute (ANSI).
    • The UNIX OS was totally written in C.
    • Today C is the most widely used and popular System Programming Language.
    • Most of the state-of-the-art software have been implemented using C.
    • Today’s most popular Linux OS and RDBMS MySQL have been written in C.

    Why Use C Language?

    C was initially used for system development work, particularly the programs that make-up the operating system. C was adopted as a system development language because it produces code that runs nearly as fast as the code written in assembly language.

    Some examples of the use of C might be −

    • Operating Systems
    • Language Compilers
    • Assemblers
    • Text Editors
    • Print Spoolers
    • Network Drivers
    • Modern Programs
    • Databases
    • Language Interpreters
    • Utilities

    C covers all the basic concepts of programming. It’s a base or mother programming language to learn object−oriented programming like C++, Java, .Net, etc. Many modern programming languages such as C++, Java, and Python have borrowed syntax and concepts from C.

    It provides fine-grained control over hardware, making it highly efficient. As a result, C is commonly used to develop system−level programs, like designing Operating Systems, OS kernels, etc., and also used to develop applications like Text Editors, Compilers, Network Drivers, etc.

    C programs are portable; hence they can run on different platforms without significant modifications.

    C has played a pivotal role as a fundamental programming language over the course of programming history. However, its popularity for application development has somewhat diminished in comparison to more contemporary languages. This may be attributed to its low−level characteristics and the existence of higher−level languages that offer a greater abundance of pre−existing abstractions and capabilities. Nevertheless, the use of the programming language C remains indispensable in domains where factors such as optimal performance, meticulous management of system resources, and the imperative need for portability hold utmost significance.

    Advantages of C Language

    The following are the advantages of C language −

    • Efficiency and speed − C is known for being high−performing and efficient. It can let you work with memory at a low level, as well as allow direct access to hardware, making it ideal for applications requiring speed and economical resource use.
    • Portable − C programs can be compiled and executed on different platforms with minimal or no modifications. This portability is due to the fact that the language has been standardized and compilers are available for use on various operating systems globally.
    • Close to Hardware − C allows direct manipulation of hardware through the use of pointers and low−level operations. This makes it suitable for system programming and developing applications that require fine-grained control over hardware resources.
    • Standard Libraries − For common tasks such as input/output operationsstring manipulation, and mathematical computations, C comes with a large standard library which helps developers write code more efficiently by leveraging pre−built functions.
    • Structured Programming − C helps to organize code into modular and easy−to−understand structures. With functionsloops, and conditionals, developers can produce clear code that is easy to maintain.
    • Procedural Language − C follows a procedural paradigm that is often simpler and more straightforward for some types of programming tasks.
    • Versatility − C language is a versatile programming language and it can be used for various types of software such as system applications, compilers, firmware, application software, etc.

    Drawbacks of C Language

    The following are the disadvantages/drawbacks of C language −

    • Manual Memory Management − C languages need manual memory management, where a developer has to take care of allocating and deallocating memory explicitly.
    • No Object−Oriented Feature − Nowadays, most of the programming languages support the OOPs features. But C language does not support it.
    • No Garbage Collection − C language does not support the concept of Garbage collection. A developer needs to allocate and deallocate memory manually and this can be error-prone and lead to memory leaks or inefficient memory usage.
    • No Exception Handling − C language does not provide any library for handling exceptions. A developer needs to write code to handle all types of expectations.

    Applications of C Language

    The following are the applications of C language −

    • System Programming − C language is used to develop system software which are close to hardware such as operating systems, firmware, language translators, etc.
    • Embedded Systems − C language is used in embedded system programming for a wide range of devices such as microcontrollers, industrial controllers, etc.
    • Compiler and Interpreters − C language is very common to develop language compilers and interpreters.
    • Database Systems − Since C language is efficient and fast for low-level memory manipulation. It is used for developing DBMS and RDBMS engines.
    • Networking Software − C language is used to develop networking software such as protocols, routers, and network utilities.
    • Game Development − C language is widely used for developing games, gaming applications, and game engines.
    • Scientific and Mathematical Applications − C language is efficient in developing applications where scientific computing is required. Applications such as simulations, numerical analysis, and other scientific computations are usually developed in C language.
    • Text Editor and IDEs − C language is used for developing text editors and integrated development environments such as Vim and Emacs.

    Getting Started with C Programming

    To learn C effectively, we need to understand its structure first. Every programming language has its programming structure. A typical structure of a C program includes several parts. The following steps show the C structure of a regular C program−

    Include Header Files

    Include necessary header files that contain declarations of functions, constants, and macros that can be used in one or more source code files. Some popular header files are as −

    stdio.h − Provides input and output functions like printf and scanf.

    #include <stdio.h>

    stdlib.h − Contains functions involving memory allocation, rand function, and other utility functions.

    #include <stdlib.h>

    math.h − Includes mathematical functions like sqrtsincos, etc.

    #include <math.h>

    string.h − Includes functions for manipulating strings, such as strcpystrlen, etc.

    #include <string.h>

    ctype.h − Functions for testing and mapping characters, like isalphaisdigit, etc.

    #include <ctype.h>

    stdbool.h − Defines the boolean data type and values true and false.

    #include <stdbool.h>

    time.h − Contains functions for working with date and time.

    #include <time.h>

    limits.h − Defines various implementation-specific limits on integer types.

    #include <limits.h>

    Macros and Constants

    Define any macros or constants that will be used throughout the program. Macros and constants are optional.

    Example

    #include <stdio.h>#define PI 3.14159intmain(){float radius =5.0;float area = PI * radius * radius;printf("Area of the circle: %f\n", area);return0;}
    Output
    Area of the circle: 78.539749
    

    Global Declarations in C

    Global declarations are optional:

    int globalVariable;
    void sampleFunction();
    

    Declare global variables and functions that will be used across different parts of the program. Take a look at the following example −

    #include <stdio.h>// Global variable declarationint globalVariable;intmain(){// Rest of the programreturn0;}

    Main Function

    Every C program must have a main function. It is the entry point of the program. Take a look at the following example −

    intmain(){float radius =5.0;float area = PI * radius * radius;printf("Area of the circle: %f\n", area);return0;}

    Functions in C

    Define other functions as needed. The main function may call these functions. Take a look at the following example:

    #include <stdio.h>// Global function declarationvoidsamplefunction();intmain(){// Programming statementsreturn0;}// Global function definitionvoidsamplefunction(){// Function programming statements implementation}

    A C program can vary from 3 lines to millions of lines and it should be written into one or more text files with extension “.c”; for example, hello.c. You can use “vi”“vim” or any other text editor to write your C program into a file.

    This tutorial assumes that you know how to edit a text file and how to write source code inside a program file.