Introduction to C
C is a general-purpose, high-level language that was originally developed by Dennis Ritchie at Bell Labs for developing the UNIX operating system. C was first implemented in 1972 on a DEC PDP-11 computer.
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 virtually all UNIX applications are 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.
About C
- C was invented to write an operating system called UNIX.
- C is based on B language, which was introduced around 1970.
- The C language standard was adopted by the American National Standards Institute (ANSI) in 1988.
- By 1973, the UNIX operating system was almost entirely written in C.
- Currently, C is the most widely used system programming language.
- Most advanced software is implemented using C.
- The most popular Linux operating system and RDBMS (Relational Database Management System) MySQL are written in C.
Why Use C?
C was initially used for system development work, particularly programs that make up the operating system. The language was adopted for its efficiency in code generation, close to assembly language, making it a preferred choice for system development. Here are some examples of its use:
- Operating systems
- Language compilers
- Assemblers
- Text editors
- Printers
- Network drivers
- Modern programs
- Databases
- Language interpreters
- Utilities
C Program
A C program can be as short as 3 lines or as long as millions of lines. It can be written in one or more files with the extension ".c", for example, hello.c. You can use "vi", "vim", or any other text editor to write your C program.
This tutorial assumes you know how to edit a text file and write source code in a program file.
C11
C11 (also known as C1X) refers to the ISO standard ISO/IEC 9899:2011. The previous C language standard was C99.
New Features
- Alignment handling (including _Alignas specifier, alignof operator, aligned_alloc function, and <stdalign.h> header).
- _Noreturn function specifier, similar to gcc's __attribute__((noreturn)).
- _Generic keyword.
- Multithreading support.
- Enhanced Unicode support. Based on the C Unicode Technical Report ISO/IEC TR 19769:2004, enhanced support for Unicode includes char16_t and char32_t data types for UTF-16/UTF-32 encoding and a header file <uchar.h> with Unicode string conversion functions.
- Removal of the gets() function, replaced with a safer function gets_s().
- Added boundary-checking function interfaces, defining new secure functions like fopen_s(), strcat_s(), etc.
- Added more floating-point processing macros.
- Anonymous structures/unions support. This was already present in gcc and is now included in the standard.
- Static assertions (_Static_assert()), processed after interpreting #if and #error.
- New fopen() mode ("…x"). Similar to POSIX O_CREAT|O_EXCL, commonly used in file locking.
- Added quick_exit() function as a third way to terminate a program. It does minimal cleanup work when exit() fails.