The C Programming Language
Almost half a century after its first appearance, C is THE programming language. The one by which (almost) all the others derived, the one always in the top two positions of the TIOBE index, the one you can program with no matter how rare or exotic is the hardware you have your hands on
C is a computer programing language first appeared on the scene 49 years ago (1972). It is a statically, weakly typed, imperative, structured programing language with manual memory management whose main purpose was to replace as much as possibile the even more low-level languages like assembly at the time used to develop those softwares that require low-level access to the hardware they run on like operating systems, file systems, communications protocols and so on.
C was invented by Dennis Ritchie at Bell Labs, and was immediately used to re-implement the Unix operating system. Today C is one of the most used programming languages of all time, and is the one most available to program with on any machine, from embedded microcontrollers to supercomputers, being a C compiler practically the first software that is developed when a new hardware is created.
The language was designed to provide low-level access to memory, has constructs that map efficiently to machine instructions and require minimal run-time support. At the same time, despite being very low-level, cross-platform portability has been one of the main goal of the language and its associated standard libraries hence its wide availability on practically any existing computer platform.
C has been standardized by the American National Standards Institute (ANSI) since 1989 and later by the International Organization for Standardization (ISO).
First glance at the code
Example: The classic "Hello world" program written in C:
Writing the classic "Hello world" program for a programming language is a consolidated practice effectively invented exactly with the introduction od the C language by Dennis Ritchie.
The program prints "hello, world" to the standard output or to a console, a terminal, a screen display or to whatever textual output the running environment provides to the application.
The original version of it is this:
Main features of C
Statically, weakly typed
C has a static but weak type system. While variables have always a type and the compiler always checks the type correctness, the programmer can override this behavior forcing casts even between incompatible types or using pointers to unions or structs to reinterpret the low-level bytes layout of the data in memory. C data types can be divided in the following categories: chars, integers, floating-point types, enumerations, arrays, structures, unions, pointers and the type void. Strings in C are arrays of chars (of one byte, there is no Unicode native support for strings in C) terminating with the character '\0'.
|unsigned char||8 bits|
|signed char||8 bits|
|int||16 or 32 bits||size of int types depends on if the hardware/operating system is 32 or 64 bits|
|unsigned int||16 or 32 bits|
|unsigned shart||16 bits|
|unsigned long||32 bits|
|float||32 bits||6 decimal places|
|double||64 bits||15 decimal places|
|long double||80 bits||19 decimal places|
Memory management in C reflects the nature of the language which is to be as close as possible to the underlying hardware the program run on. As such the language offers three main low-level way to manage the memory for the data that programs use, the study of which is very useful even for non C programmers to understand why and how other languages offers built-in automatic memory management. Acquiring this knowledge also educate programmers on how to avoid pitfalls and fallacies when using those systems.
C libraries can be divided into three main categories: the C standard library which is specified by the ISO and ANSI C standards and comes with every C implementation; the C library functions specifically targeted for Unix and Unix-like systems, detailed in standards such as POSIX and the Single UNIX Specification, and all the other libraries of the world written in C, which are quite a lot because usually when a high level language need to access low-level functionalities, these are accessed in C and then interfaced with the high level language.
This is where C really shines! This is a language that was invented to replace the very low-level (and very hard to program with) assembly but without sacrificing the performance. Getting optimal executions speed was a key goal while designing C because this was the language the entire Unix system would be rewritten with. The goal was completely achieved, and still today it's very rare, even when programming very low-level system softwares, the necessity to resort to assembly to get more speed.
Another key strength of C is that to run the programs there is no need of any runtime support. The programs are compiled to machine code and the code from libraries are also inserted into the same program which in the end results is a unique file that contains in itself all the things that the program needs in order to run. Same reusable parts of the code can also be organized in platform dependant external libraries, like the DLL in Windows systems or the Shared Objects (*.so) files in Linux systems, but then again these are machine code compiled too.
Notable softwares/platforms/products written in C
- Operating Systems Almost all of the Operating Systems on the market today are still written in same or most parts in C: Windows, Linux, Mac OS X, iOS, Android and so on
- Hardware drivers are usually written in C
- Many other programming languages are written in C. For example Python is written in C
- Googe, Facebook and many, many other organizations use pure C for functionalities for which the maximum possibile execution speed is really neeeded
Best books for learning C
|C Programming Absolute Beginner's Guide (3rd Edition)|
The fastest way to get comfortable with CThis is today’s best beginner’s guide to writing C programs–and to learning skills you can use with practically any language. Its simple, practical instructions will help you start creating useful, reliable C code, from games to mobile apps. Plus, it’s fully... (continue on Amazon)
For experienced programmers
|Advanced Topics in C: Core Concepts in Data Structures (Expert's Voice in C)|
Concepts that any programmer should knowYou will increase the range of problems you can solve when you learn how to manipulate versatile and popular.... (continue on Amazon)
There are many reasons why after almost 50 years from its born C is still the most used programming language of the world, but there is only one for you to learn and use it: to really learn computer programming nothing is better than learning to program in C.