Dennis Ritchie
C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, while a static type system prevents unintended operations.
By design, C provides constructs that map efficiently to typical machine instructions, and has found lasting use in applications previously coded in assembly language.
Such applications include operating systems, as well as various application software for computers ranging from supercomputers to embedded systems.
C was originally developed at Bell Labs by Dennis Ritchie between 1972 and 1973 to make utilities running on Unix.
Later, it was applied to re-implementing the kernel of the Unix operating system.
Many of the C projects that exist today were started decades ago.
The UNIX operating system’s development started in 1969, and its code was rewritten in C in 1972. The C language was actually created to move the UNIX kernel code from assembly to a higher level language, which would do the same tasks with fewer lines of code.
Oracle database development started in 1977, and its code was rewritten from assembly to C in 1983. It became one of the most popular databases in the world.
In 1985 Windows 1.0 was released. Although Windows source code is not publicly available, it’s been stated that its kernel is mostly written in C, with some parts in assembly. Linux kernel development started in 1991, and it is also written in C. The next year, it was released under the GNU license and was used as part of the GNU Operating System. The GNU operating system itself was started using C and Lisp programming languages, so many of its components are written in C.
But C programming isn’t limited to projects that started decades ago, when there weren’t as many programming languages as today. Many C projects are still started today; there are some good reasons for that.
Microsoft Windows
Microsoft’s Windows kernel is developed mostly in C, with some parts in assembly language. For decades, the world’s most used operating system, with about 90 percent of the market share, has been powered by a kernel written in C.
Linux
Linux is also written mostly in C, with some parts in assembly. About 97 percent of the world’s 500 most powerful supercomputers run the Linux kernel. It is also used in many personal computers.
Mac
Mac computers are also powered by C, since the OS X kernel is written mostly in C. Every program and driver in a Mac, as in Windows and Linux computers, is running on a C-powered kernel.
Mobile
iOS, Android and Windows Phone kernels are also written in C. They are just mobile adaptations of existing Mac OS, Linux and Windows kernels. So smartphones you use every day are running on a C kernel.
The alarm clock that wakes you up is likely programmed in C.
Then you use your microwave or coffee maker to make your breakfast.
They are also embedded systems and therefore are probably programmed in C.
You turn on your TV or radio while you eat your breakfast. Those are also embedded systems, powered by C.
When you open your garage door with the remote control you are also using an embedded system that is most likely programmed in C.
1972
C was created by Dennis Ritchie at Bell Labs.
1978
Brian Kernighan and Dennis Ritchie published the first edition of "The C Programming Language", known as K&R C or C78.
1989
ANSI C was standardized, introducing several new features and clarifying ambiguities in earlier versions.
1990
The ANSI C standard was adopted internationally as C89/C90.
1995
ISO published an extension called Amendment 1 for the ANSI-C standard, known as C95.
1999
ISO/IEC 9899:1999, commonly referred to as C99, was published, introducing several new features like inline functions, new data types, and variadic macros.
2011
ISO/IEC 9899:2011, known as C11, was published, adding features like type generic macros, anonymous structures, improved Unicode support, atomic operations, multi-threading, and bounds-checked functions.
2018
ISO/IEC 9899:2018, called C17, was published, introducing no new language features but only technical corrections and clarifications to C11.
Expected 2024
ISO/IEC 9899:2024, informally called C23, is expected to be published, introducing 14 new keywords.
The C programming language has undergone significant evolution since its creation in 1972, with each revision adding new features and capabilities while maintaining compatibility with previous versions. These standards have played a crucial role in the language's widespread adoption and continued relevance in the field of software development.
First open your terminal.
Type your program.
Then type:- gcc <filename>.c -o <outputfile>.out
Then run your first program by typing:- ./<outputfile>.out
A computer program is a list of "instructions" to be "executed" by a computer.
In a programming language, these programming instructions are called statements.
The following statement "instructs" the compiler to print the text "Hello World" to the screen:
printf("Hello World!");
It is important that you end the statement with a semicolon ;
If you forget the semicolon (;), an error will occur and the program will not run:
Most C programs contain many statements.
The statements are executed, one by one, in the same order as they are written:
Example
printf("Hello World!");
printf("Have a good day!");
return 0;
A header file is a file containing C declarations and macro definitions to be shared between several source files.
You request the use of a header file in your program by including it, with the C preprocessing directive ‘#include’.
#include <stdio.h>
stdio.h is a standard library header file in C that provides access to a variety of input and output functions, macros, and variables. It is one of the most commonly used header files in C programming.
1. Input/Output Functions: stdio.h includes functions like printf(), scanf(), fopen(), fclose(), and many others that allow for reading from and writing to the console, files, and other input/output streams.
2. Macros and Data Types: The header file defines macros like EOF (end of file), NULL, and BUFSIZ, as well as data types like FILE, size_t, and fpos_t that are used for input/output operations.
3. Portability: The functions and macros in stdio.h are standardized and work across different platforms and operating systems, making C code more portable.
4. Ease of Use: The stdio.h functions are relatively simple to understand and use, especially for beginners learning C programming.
The main() function is the first function in your program that is executed when it begins executing, but it's not the first function executed.
The first function is _start(), which is typically provided by the C runtime library, linked in automatically when your program is compiled.
The main() function has two arguments that traditionally are called argc and argv and return a signed integer.
Most Unix environments expect programs to return 0 (zero) on success and -1 (negative one) on failure.
The main method shall have one of the following forms:
Curly braces are used to enclose a block of code, such as the body of a function, loop, or conditional statement.
Variables declared within a block are only valid until the end of that block, marked by the closing curly brace }.
It is considered good practice to consistently indent the code inside curly braces to improve readability and make the code structure clear.
Many code editors and IDEs can automatically format code with proper indentation when curly braces are added.
An opening curly brace { must always have a matching closing curly brace } for the code to be valid and compile correctly.
Unbalanced braces can lead to compiler errors that can be difficult to debug, especially in large programs.
Comments in C programming are used to add explanatory notes, disable code, or provide documentation. There are two main types of comments in C:
Single-line Comments
Single-line comments begin with // and continue until the end of the line.
Example:
// This is a single-line comment
Multi-line Comments
Multi-line comments begin with /* and end with */. They can span multiple lines.
Example:
/*
* This is a multi-line comment.
* It can contain multiple lines of text.
*/
Uses of Comments
Explaining Code: Comments are used to describe the purpose, functionality, and behavior of code segments.
Documenting Code: Comments can provide detailed documentation for functions, variables, and data structures.
Disabling Code: Developers can temporarily disable code by enclosing it within multi-line comments or adding // at the beginning of each line.
Debugging: Comments can be used to isolate and debug specific parts of the code.
Best Practices for Comments
Be concise and clear: Comments should be brief and easy to understand.
Avoid stating the obvious: Comments should explain the "why" rather than the "what" of the code.
Keep comments up-to-date: Update comments whenever the code changes to avoid confusion.
Use consistent formatting: Follow a consistent style for comment formatting within a codebase.
Use comments sparingly: Overuse of comments can make the code harder to read. Aim for self-explanatory code.
In summary, comments in C are essential for documenting, explaining, and debugging code. They help make code more readable and maintainable for both the original author and other developers working on the project.