Introduction to C Programming Language

Prerequisites

  • Basics of Computer and Operating System
  • Mathematics
  • Binary Numbers and Decimal Numbers
  • Programs, Software, Internet, etc.

History of C

 

The development of Unix in the C language make it uniquely portable and improvable.

 

The first version of Unix was written in the low-level PDP-7 assembler language. Soon after, a language TMG was developed for the PDP-7 by R. M. McClure. Using TMG to develop a FORTRAN compiler, Ken Thompson instead ended up developing a compiler for a new high-level language he called B, based on the earlier BCPL language developed by Martin Richard. Where it might take several pages of detailed PDP-7 assembly code to accomplish a given task, the same functionality could typically be expressed in a higher level language like B in just a few lines. B was thereafter used for further development of the Unix system, which made the work much faster and more convenient.

When the PDP-11 computer arrived at Bell Labs, Dennis Ritchie built on B to create a new language called C which had a powerful mix of high-level functionality and the detailed features required to program an operating system. Most of the components of Unix were eventually rewritten in C in 1973. Because of its convenience and power, C went on to become the most popular programming language in the world over the next quarter century.

 

Introduction to C

C Basics

C is a middle level language where we can perform high level operation as well as low level operations.

 

Characteristics of C

We briefly list some of C’s characteristics that define the language and also have leads to its popularity as a programming language. Naturally we will be studying many of these aspects throughout the course.

  • Small size
  • Extensive use of function calls
  • Structured language
  • Low level (BitWise) programming readily available
  • Pointer implementation – extensive use of pointers for memory, array, structures and function.

C has now become a widely used professional language for various reasons.

  • It has high-level constructs.
  • It can handle low-level activities.
  • It produces efficient programs.
  • It can be compiled on a variety of computers.

Its main drawback is that it has poor error detection which can make it off putting to the beginner. However diligence in this matter can pay off handsomely since having learned the rules of C we can break them. Not many languages allow this. This if done properly and carefully leads to the power of C programming.

 

The standard for C programs was originally the features set by Brian Kernighan. In order to make the language more internationally acceptable, an international standard was developed, ANSI C (American National Standards Institute).

 

C Program Structure

 

Preprocessor commands

Global declaration

int main() {

Statements

——-

——

}

  • Preprocessor Commands:

These are the instruction which we want to give to our compiler (Its preprocessor).
They indicate how the program is to be compiled.
A preprocessor commands Starts with the symbol #.
e.g. #include, #define, #ifdef

  • Global declaration:

In this section we can define variables, functions; structures etc.
Variables define in this section are accessible anywhere within the program.

  • Function main():

This is the entry point of our program.
Execution of the program begins with function main().

So a C program must contain at least one function i.e. main.

 

Sample C Program

 

#include <stdio.h>

int main() {

printf(“Hello World \n”);

exit(0);

}

 

NOTE:

  • C required a semicolon at the end of every statement.
  • printf() is a standard C function — called from main.
  • \n signifies new line. Formatted output – more later
  • exit() is also a standard function that causes the program to terminate. Strictly speaking it is not needed here as it is the last line of main() and the program will terminate anyway.

Leave a Reply

Your email address will not be published. Required fields are marked *