An Overview of C


Introduction

C language is undoubtedly one of the most widely used programming languages for software development. The language was invented by Dennis Ritchie at the Bell Laboratories in the early 1970’s.He used C to write Unix, the highly popular operating system. C was based on an earlier language called B written by Ken Thompson. B, in turn, was an adaptation of a language known as Basic Combined Programming Language (BCPL).

Features of C

C is a general-purpose structured programming language. You divide a program into modules (a collection of functions) that communicate with each other through function calls. This process of breaking up a program into modules is called modularization.

C is powerful as well as efficient. It has high-level as well as low-level programming features. It allows programmers to closely interact with the inner workings of the computer. Hence it is well suited for writing both system software and application programmes. C is portable. Therefore, C programs written for one computer can be executed on another with minimal changes or none.

The power and efficiency of C programs come from the availability of a rich set of data types, operators and several standard built-in functions. C is a free-form language. That is, the compiler does not care where on the line you begin typing.

C Programming Basics

Let’s examine some fundamentals, which you need to know while writing a C program. We start with a simple C program that prints a welcome message to the screen.

#include

void main(){

printf(“Welcome to C programming!”);

}

Output: Welcome to c programming!

program 1.1

The program should be saved in a file with extension ‘.c ‘.The first line of the program is a preprocessor directive. ‘stdio.h’ refers to the standard I/O header file, which contains the information of the standard input and output functions. The #include directive allows the programmer to include any header file into his program so that he can make use of the various library functions. The availability of such built-in functions makes C programming very easy.

The second line of the program defines a function named main. Every C program must have a main function. The execution of every C program starts with the main function. It can be called as the entry point of the C program. The word main is followed by an empty pair of parentheses. It indicates that the main function has no arguments. The statements that comprise the function should be enclosed within curly braces ({}). The content of the curly braces is called the body of the function. In this program, the function body consists of just one statement - printf(“Welcome to C programming!”).The end of the statement is indicated by a semicolon. In C, it is compulsory to terminate all statements with a semicolon. This statement invokes the standard library function printf( ). The printf( ) function is used to print a message to the screen. The printf( ) function has a single argument, which is a character string (a sequence of characters enclosed within double quotes - Welcome to C programming!”).When invoked, the function prints the character string to the output screen.

Comments in C

Comments are used as a means for internal documentation of a program. They serve as explanatory remarks to any one who reads the program. A comment starts with the characters /* and ends with the characters */.

Example: /* This is a comment */

Comments are ignored by the compiler. They have no say in the execution of a program.

The C Preprocessor

Every C program, before compilation, is first processed by a program called preprocessor. The function of the preprocessor is to modify the C source code according to the preprocessor directives given in the program. The preprocessor doesn’t alter the original source file but creates a new file, which contains the processed version of the program. This file is submitted to the compiler for compilation.

Preprocessor Directives

The preprocessor directives are instructions given to the preprocessor. All preprocessor directives should be placed before the main function. All directives start with a ‘#’ symbol. The most commonly used directives are #include and #define. A detailed look into the use of preprocessor directives will be made at the end of this book.