C is a general-purpose high-level programming language originally developed by Dennis Ritchie at AT & T’s Bell Laboratories (USA) in 1972. It was mainly developed as a system programming language to build an operating system. One of the main features of C includes low-level memory access, a set of simple keywords, which makes C a suitable language for making system applications like operating systems or compilers.
C is a compiled language. A compiler is a compiler program that translates programs written into a high-level programming language to a low-level language. In general, a compiler converts your written program into a form that your computer could understand. A computer understands everything in the form of binary statements (i.e., in the form of 0’s and 1’s only), but the code is written in the form of English language keywords. So a compiler acts as a converter that translates your program.
Structure of a C program
printf("Roses are red.");
When this program is successfully compiled, it should give the following output:
Roses are red.
Let’s look at the program components closely
Inclusion of header file/files: A header file is always included at the top and hence called a header file. A header file is a collection of inbuilt functions and templates that can be used in the program once the file is included. Here the file stdio.h stands for “standard input and output”. It contains all the necessary functions for taking input from the user and giving output to the user.
The main() function: A function is a block of code that can be used again and again. The code inside a function executes only when the function gets called. Every C program starts execution with the main function. The main function is just like a normal function. The difference is that the main function automatically gets called by the operating system every time the program runs.
The printf function: printf is an inbuilt function in C, which is used to show some sort of output. This function is a part of stdio.h header file and accepts string arguments, variables, pointers, and separate expressions.
return 0: Every function has a return type. It simply means what type of value the function would return if it’s meant to return. You will get to know what a return type is once you’ll learn what a function is.
Keywords used in C
‘Keywords’ or ‘Reserved Words’ are those predefined words that are meant for the compiler/interpreter. There are 32 keywords in C. They are-
Features of C
- Simple language – C is a simple language because it provides a structured approach.
- Portability – C is a machine-independent language because its programs can be executed on different operating systems with some machine-specific changes.
- Structured language – We can break apart a C program into parts using functions. So it can be said that C is a structured programming language.
- Execution Speed – Because of lesser inbuilt functions, the compilation and execution time of C is comparatively fast.
- Mid-level programming language – C is intended to do tasks related to machine-level or low-level programming, but it also has the features of a high-level programming language. Therefore C can be called a mid-level programming language.
- Rich library – The language provides a rich set of inbuilt functions contained in various libraries.
- Recursion – Recursion is a process in which a function can be called inside itself.
- Pointers – C supports the concept of pointers. A pointer is a special type of variable that can store the address of another variable. We can use pointers to interact with the memory.
Applications of C
Some common applications of C are:
- Compiler design
- Operating system
- UNIX Kernel
- Spreadsheet software
- Browser design
- Database design
- new programming language.