The Wonderful C Programming Language

What is C Programming Language

The C programming language is a general-purpose, imperative (procedural) and structured computer programming language that was developed in the early 1970s. It has been standardized by ANSI and ISO. The most common use of the C programming language is system software on most computing platforms.

C is one of the first compiled languages for which a compiler without any intermediate code was published: its authors opted to make it a high-level assembly language instead. It is particularly suited to write source code, which can then be compiled into machine language object files for a particular machine. In most cases the machine-specific code was written by a human in a high level language such as C or Fortran. This source code can be read and edited by humans, but its compilation to run on the target hardware must be done using special tools.

The C programming language is closely related to the C++ programming language, mainly because many of its early implementations were themselves originally written in C.

History of C

C was invented in 1972 at AT&T Bell Labs by Dennis Ritchie; it is a very popular computer-programming language. It was originally used to port the operating system UNIX from the PDP-7 and PDP-11 to the Motorola 68000 CPU. C soon proved to be a more flexible language than was previously possible with FORTRAN or LISP, and it became widely popular for projects requiring speed and efficiency. The first widely distributed application was the UNIX operating system, which was written in C.

Later, C became the programming language of choice for embedded systems in consumer electronics. It has been widely used by Linus Torvalds, the founder of Linux and the creator of the GNU operating system (see below). In fact, many applications that now appear to be written in C were originally written in assembly language before they were translated into C using a compiler.

Benefits of Using C

C was designed to be a compiled, efficient language for systems programming. It is a procedural language that supports structured programming, recursion and lexical variable scope. It has an extensive library of functions, which is one of its great strengths.

The C programming language has the following benefits:

– It provides a set of data types for integers, floating-point numbers and characters.

– It includes functions for arithmetic operations, file manipulation and string processing.

– It has an array data type, which allows for easier handling of arrays, strings and pointers.

– It provides a function for condition checks that enables the programmer to write generic routines.

– The functions provided in the library allow for method calls and recursion.

The Disadvantages of C Programming Language

– Its use of the global scope makes it unsuitable as a general purpose language, not suitable for high-level programming.

– Its keywords make it unsuitable for both learning and teaching purposes.

– It has no classes, inheritance or polymorphism.

– It doesn’t include a GUI library.

Features of C

The C programming language includes the following features:

– It is procedural language, which means that it is based on procedures and functions instead of objects.

– It supports structured programming, in which code is written as a series of functions. These functions are called by other functions (or user-defined subroutines) to perform some operation or to carry out some task or algorithm.

– It supports a high-level data type called an array, which is a variable that can store many values of the same type.

– It supports lexical variable scope, in which local variables have a limited scope to the procedures in which they are defined. This means that all of the local variables defined in one procedure cannot be accessed by any other procedure.

– It has exception handling and parameterized types.

IDEs for C

C can be typed or scrolled editor which is based on emacs and vi. It also has its own IDE and compiler.

The following are some IDEs for C:

  • vim,
  • Eclipse,
  • NetBeans,
  • DataGrip,
  • Qt Creator

C Compilers

The compilers are GNU C/C++ Compiler which is a free compiler and the GCC. The GCC is the most widely used C compiler in the world. The CLANG is an open source C compiler for Mac OS X and iOS. C is a so-called statically typed language. In this language, the compiler checks the program to make sure that variables used in the program do not have other variables with the same name. This is known as type safety. This is useful because if a variable name has been used before, then it is possible that something bad could happen when it is used again.

C Libraries

The C language supports a number of built-in functions, but its functionality can be greatly extended through the use of numerous libraries; some of the commonly used ones are:

– The C standard library, also called the ISO/IEC 9899:1999 library. It provides many basic functions that every C program needs.

– The ANSI/ISO C library. It is an extension of the ISO/IEC 9899:1999 library for support of Windows and UNIX platforms.

Some of the most commonly used C libraries are:
– Standard C Library: This library provides most of the functions that can be used in all languages.

– Standard Template Library: This library provides classes for managing and processing objects such as containers, iterators, maps and queues.

– POSIX Thread Library: This is a POSIX shared library that allows C code to create and manage threads.

– Windows API (Windows API): This is an official Microsoft C/C++ binding that provides a complete interface to the components of the operating system.

Standard C Libraries

The following are the standard libraries of C programming language. They generally predate the inclusion of C standard but are still in use. However, more modern libraries such as those defined by POSIX or Windows may be preferred over the older ones below.

The following are part of the standard C library:
– Memory functions: These functions work with the contents of memory and with pointers to memory locations.

– Mathematical functions: These functions provide mathematical operations including trigonometric, elliptic curve, and finite difference computations.

– Character handling functions: These functions deal with single characters and strings of characters such as arrays (C has a built-in type of character array).

– Input/output functions: These functions provide input and output capabilities from standardized I/O streams.

– Time handling functions: These are for handling time through the system clock, including time conversions (such as to and from Coordinated Universal Time) and dealing with calendar dates.

– String handling functions: These functions are related to strings and character arrays.

C Libraries for Threading

The following are some of the C libraries that provide functionality for threading programming:
– POSIX Threads Library (PThreads): The POSIX threads library is an application programming interface that enables the user to create and control multiple threads of execution.

– Win32 API: The Win32 API is a set of extensions to the Microsoft Windows API which is part of the Visual C++ package (this is included with Visual Studio).

C programming language defined: The C programming language was designed for system programming, as a low-level language that could be directly compiled into machine code.

Operating Systems and C Language

There are several operating systems that support the C programming language. Some of them are:
– Linux: The Linux operating system was derived from Unix and is widely deployed in many different areas including as a general purpose server platform, media centre and as an embedded operating system. It includes all of the necessary tools for C programming including compilers, source code debugger and text editors.

– Windows: The Windows operating system is the most widely deployed operating system in the world. It supports a wide variety of hardware platforms including embedded devices, such as cell phones, PDAs and appliances.

– Apple Mac OS X: The Macintosh operating system was introduced in 1984 and has been a significant player in the computer market ever since. This operating system is available on many different hardware platforms ranging from Macbook to iMacs and iBooks.

– Android: The Android mobile device platform is based on Linux 2.6 and has been extended for mobile applications. It is developed by Google, and the open source code is available through the Apache 2 product license.

– Apple iOS: The iOS operating system powers iPhones, iPods and iPads. It was originally developed for the iPhone, but it has been replaced with its successor IOS 7 in 2013.

– BlackBerry OS: BlackBerry OS was originally developed by Research in Motion (RIM) for their BlackBerry devices.

Drivers and C Language

The following are the C drivers that are some of the most popular:
– USB: This is a universal serial bus (USB) implementation of C standard. It allows for communication between hosts and devices via a standard set of control commands.

– Audio: This C library allows for input and output of sound via various audio devices such as sound cards, speakers, microphone, etc.

– Video: This C library allows for input and output of video through various graphics cards, monitors, etc.

– EIDE: The Enhanced IDE disk driver is an enhanced interface to IDE (Integrated Drive Electronics) hard disks. It includes support for ATAPI drives as well as older IDE drives.

– Ethernet: The Ethernet library allows C programs to communicate with any TCP/IP network device that supports the IEEE 802.3 protocol using Ethernet transceivers and hubs.

Software Written in C Language

The following are some of the software written in C programming language:
– Linux kernel (C)
– Cisco PIX firewall (C)
– GSM (GSM GPRS Core Network) protocol stack (C, C++)
– Bill of materials (C, C++)
– x86 Power Management Framework (C++, Java, .net)

C remained popular for system programming until the advent of the graphical user interface (“GUI”).

Syntax of the C Language

The following are some syntactical rules followed in C language. Here, we will consider a single statement such as:
printf(“Hello, World!”);
Here, we will discuss the various components of this statement separately: All the statements in C are ended with a semicolon. There is also a “white space” (spaces, tabs, alignment and symbolic constants) for formatting. The name of the function that has been called here is “printf” that prints formatted text to the output console. The “Hello, World!” is a string argument that has been used as an input argument to the function printf.

There are several predefined keywords for the C language, for example : “int”, “float”, “char”, “char*”, etc. These are called reserved words, and they cannot be used as variable or function names in C, and therefore they should not be used as variable or function names in a program.

C programming language includes two types of comments:
– /* … /: This is called multiline comment, and it can span over multiple lines. The / is called the delimiters. In C, multiline comments can directly follow if-statements and for-change statements.

– // : This is called single line comment, and it is used to make a line of text to be a comment and not a command.

Operators

In C programming language there are number of operators that are used to modify and perform calculations. Some of them are as follows:

– “++”; The incrementation operator works like that of other languages like C++ and Java. In this case, the value being assigned is increased by 1.

– “–“; The decrementation operator works like that of other languages like C++ and Java. In this case, it decreases the value being assigned by 1.

– “+”, “-“, “*”, “/”, “%” : These are the arithmetic operators that works as expected, i.e., + signs for addition, – for subtraction and so on. The last one is an operator for remainder. This is used to find remainder of any integer division without requiring any modulus operator (i.e. %). It works only for integer division (i.e., while working with integers).

– “<<“, “>>” : These are the bitwise shift operators, which perform left and right integer bits shifting operations respectively, and they are often used in mathematics and programming.

Hello World! Example

The standard hello-world in C language can be implemented like this:

#include <stdio.h>
int main(void)
{
    printf("hello, world\n");
}

The C Data Types

There are number of data types that are used in C programming language. Some of them are listed here:

Integers and Floating Point

In C, integers are represented by the keyword “int”, and floats are represented by the keyword “float”. Integers can be signed if they have their own individual value (i.e. there can be more than one value for them; usually this is true for integers that have a sign but no decimal point), otherwise they’re unisex.

Boolean Data Types

C has two boolean data types: true and false. The use of these data types depends on the context in which they’re used. For example, they’re used as integer values for bitfields of integer arrays, and in the case of floating point variables, they’re used to represent values.

Character Strings and String Data Type

The character string is a sequence of printable characters terminated by a “\” character. The string data type is used to work with them in C.

Arrays

C arrays are homogeneous collections of variables. In other words, all the elements of an array should belong to the same data type. Arrays can be one-dimensional or two-dimensional and can hold any type of data object.

Pointers

Pointers are the programming mechanisms that are used in C programming language to refer to variables and functions. There has been an evolution of the concept of pointers through various similar languages. These pointers allow a programmer to perform operations which is otherwise impossible.

Structures, Unions, and Enumeration

Structures and unions are collections of data items that can have different data types.

C-Like Languages

The following are programming languages that are derived from C language:
– C++: This is a general-purpose, object-oriented programming language. This is standardized by the ISO/IEC standard.
– Java, C# and others: These are general-purpose programming languages for the developers. This is supported by Microsoft, IBM, Oracle and some other vendors.
– Perl: This is a general-purpose and powerful language (more than just another scripting language). In C-like languages, the concept of pointers is called “references”. This language did not follow the C-style naming conventions.
– Python: This is a simple yet powerful and flexible programming language, and it has been widely used for various applications. Most of the Python code looks similar to C programs.
– Tcl: This is another general purpose programmable interpreted scripting language written in C, like Perl, Python and Java.
– Objective-C: This is a C-like language developed by Apple for writing applications for their systems.

  • D: This is a dynamically typed, imperative programming language. It uses syntax resembling that of C for implementing data structure and algorithms.

The Future of C Programming Language

The C language was once popular for system programming. However, with the emergence of the graphical user interface (“GUI”), it was replaced by more modern languages such as Basic, Visual Basic, and Java. Many compiler vendors continue to provide C support to running Unix systems as a way to manage legacy code bases.

C has been evolved into C++ and Java, in order to support object-oriented programming.

C++ is a superset of C, which means that it can run any C program. However, when the language was changed it was named as C++ so that every time a developer used C they will think about the new feature in the language. There are few changes in C language which made it more powerful and hence, used by developers for system programming and desktop applications.

C++ is an object-oriented programming language derived from the C language and widely used in software development. It supports the creation of sophisticated user interfaces that make use of more modern libraries and graphics. The C++ standard by ISO/IE is an extensive guideline for this programming language. The C++ programming language is based on the concepts of inheritance, mixins, virtual functions, templates and dynamic memory allocation.

C# is a general purpose imperative programming language developed by Microsoft more than 20 years ago for use with their MS Windows operating systems.

International Obfuscated C Code Contest

The International Obfuscated C Code Contest (IOCCC) is a programming contest in which the source code of the program must be difficult for humans to understand and maintain, but still be valid C code. Obfuscation usually involves the use of undeclared variables and names which have special meaning to human readers, but are meaningless to a person trying to understand the code.

CWEB

CWEB project was a web programming framework that ran on top of C. It was thought to be safe and easy to use. It had been used in several commercial products, but its popularity faded in later years.

C++0x

Also known as C++0x, this new version of the C++ programming languages was released in 1999 by the ISO and is similar to modern-day C++. This version of C++ includes support for templates, which allow code reuse through a parameterized type. The standard has also been increasing its coverage of the ISO/IEC International Standard Programming Languages.

C++23

This is a next version of C++ to be released in the future. It will contain many libraries, as well as new features such as Literal suffixes, member function: contains, header: stdatomic.h and a stacktrace library.

Things to Remember

Below are some of the points that you should remember:

The source code of most operating systems is written in C or C++. You can also write applications for Windows in C or C++.

C programming language has been around for a long time and continues to be one of the most popular languages available.

There is a web-based tool named C-shell for Linux. It was originally developed by the group at Softweyr. It is designed to be a small (under 4MB) Unix-like shell suitable for use in embedded systems and other time-constrained environments.

C++ is a relatively modern and well established language that has been used in both commercial products, as well as practical software projects over the years.

Many C++ compilers and runtime environments are available on Linux. A complete list of such tools is available at Programming Languages By Machine: C and C++.

The web programming framework named CWEB was originally designed to be a safe and easy way to write an article to document the making of the source code created by Donald Knuth & Silvio Levy.

For decades, the Internet Engineering Task Force (IETF) has been developing and using their native variant of the C programming language along with several other languages in order to develop and maintain their services.

For more, read PC Ocular magazine articles regularly.

Benkő Attila is a Hungarian senior software developer, independent researcher and author of many computer science related papers.

Leave a Reply