, , , , , , , , , , ,

C Overview
C is a programming language developed at AT&T’s Bell Laboratories of USA in 1972. C was originally first implemented on the DEC PDP-11 computer. It was designed and written by a man named Dennis M. Ritchie. In the late seventies C began to replace the more familiar languages of that time like PL/I, ALGOL, etc.

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 essentially all UNIX applications programs have been written in C. Possibly why C seems so popular is because it is:

  1. Easy to learn
  2. Reliable
  3. Structured language
  4. Simple in use
  5. It can compiled on a variety of computer platforms

Why to use C?
In an industry where newer languages, tools and technologies emerge and vanish day in and day out, a language that has survived for more than 4 decades has to be really good. C was initially used for system development work, the programs that make-up the operating system (because it produces code that runs nearly as fast as code written in assembly language).

Mobile phones, palmtops and tablets are becoming increasingly popular. Also, common consumer devices like microwave oven, washing machines are getting smarter by the day. This smartness comes from a microprocessor, an operating system and a program embedded in this devices. These programs not only have to run fast but also have to work in limited amount of memory. No wonder that such programs are written in C. With these constraints on time and space, C is the language of choice while building such operating systems and programs.

Mostly C is used for the development of:

  1. Operating Systems
  2. Compilers
  3. Interpreters
  4. S/w, H/w & N/w Drivers
  5. Text Editor

C Program Structure
Before we begin with our first C program do remember the some rules that are applicable to all C programs.

A C program basically consists of the following parts:

  1. Preprocessor Commands
  2. Functions
  3. Variables
  4. Statements & Expressions

Some rules for C Program:

  • Each instruction in a C program is written as a separate statement.
  • The statements in a program must appear in the same order in which we wish them to be executed.
  • Blank spaces may be inserted between two words to improve the readability of the statement. However, no blank spaces are allowed within a variable, constant or keyword
  • All statements are entered in small case letters.
  • Every C statement must end with a ;. Thus ; acts as a statement terminator.

Let us look at a simple program:

#include < stdio.h >

void main()
   /* my first C program */
   printf("Hello! How r u?");

Let us look various parts of the above program:

  1. The first line of the program is a preprocessor command, which tells a C compiler to include stdio.h file before going to actual compilation.
  2. The next line int main() is the main function where program execution begins.
  3. The next line /*…*/ will be ignored by the compiler.such lines are used to comments in the program.
  4. The next line printf(…) is another function available in C which causes the message “Hello, World!” to be displayed on the screen.

Compilation and Execution
Once you have written the program you need to type it and instruct the machine to execute it. To type your C program you need another program called Editor. This program needs to be converted to machine language that the machine can execute it. For this you need another program called Compiler.

Turbo C or Turbo C++ are some IDE which consists of an Editor as well as the Compiler.

Follow the steps given below to compile and execute your first C program… (Using Turbo C or Turbo C++ Compiler)

  1. Start the compiler at C> prompt.
  2. Select New from the File menu. Type the program
  3. Save the program using F2 with a proper name
  4. Use Ctrl + F9 to compile and execute the program.
  5. Use Alt + F5 to view the output.