Wednesday, 27 July 2011

starting with c

C basics

Before we embark on a brief tour of C's basic syntax and structure we offer a brief history of C and consider the characteristics of the C language.
In the remainder of the Chapter we will look at the basic aspects of C programs such as C program structure, the declaration of variables, data types and operators.

History of c

C is a programming language developed at AT & T’s Bell Laboratories of USA in 1972.
The milestones in C's development as a language are listed below:

• UNIX developed DEC PDP-7 Assembly Language
• BCPL -- a user friendly OS providing powerful development tools 

                developed from BCPL. Assembler tedious long and error prone.
• A new language ``B'' a second attempt. come in 1970.
• A totally new language "C" a successor to ``B''. comes in 1972
• By 1973 UNIX OS almost totally written in ``C''.

Characteristics of C

We briefly list some of C's characteristics that define the language and also have lead 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.
• Loose typing unlike PASCAL.
• Structured language.
• Low level (BitWise) programming readily available.
• Pointer implementation - extensive use of pointers for memory, array, structures and


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.

What is a Computer Program?

A program is a set of step-by-step
instructions to the computer telling it to
carry out the tasks that you want it to do
to produce the results you want.

What is Programming?

• Programming consists of two distinct
• algorithmic design (the problem solving
  stage, analogous to the work of an
  architect designing a building)
• coding (the construction phase)

Levels of Programming Languages

• Machine language
• Assembly Language
• High Level Languages

Machine Language

• Actual binary code that gives basic
  instructions to the computer.
• These are usually simple commands
  like adding two numbers or moving
  data from one memory location to
• Different for each computer processor

Assembly Language

• A way for humans to program computers
  directly without memorizing strings of binary
• There is a one-to-one correspondence with
  machine code.For example ADD and MOV are mnemonics for
  addition and move operations that can be specified
  in single machine language instructions.
  Different for each computer processor

High-level language

• Permits humans to write complex
  programs without going step-by step.
• High-level languages include Pascal,
  FORTRAN, Java, Visual Basic, and
  many more.
• One command in a high-level
  language may translate to tens of
  machine language instructions.


Computers can only run machine language
programs directly.
Assembly language programs are assembled, or
translated into machine language.
Likewise, programs written in high-level languages,
like Java, must also be translated into machine
language before they can be run. To do this
translation compile a program.

Structured Programming

Structured Programming is a technique for organizing 

and coding computer programs according to the hierarchy of modules is
used, each having a single entry and a single exit point, 

and in which control is passed downward through the structure.

Programming language C

• C is a general purpose programming language.
• C is a middle level language.
• C is a structured language

Why C is called “a middle level language”?

C contains the features of high level language
portability ,it is easy to adapt software written
for one type of computer to another type. 

the and also the functionality of low level language.
for i.e operators such as &, |,>,< etc. simulate to low level instruction codes.
in term of direct manipulation of bits, bytes and addresse 

Writing C Programs 

• A programmer uses a text editor to create or modify files containing C code. 
• Code is also known as source code. 
• A file containing source code is called a source file. 
• After a C source file has been created, the programmer must 
  invoke the C compiler before the program can be executed (run). 

Invoking the turbo c Compiler 

At the prompt, type tcc pgm.c where pgm.c is the C program source file. 

There is a better way use IDE instead of command for creating programs.

The Result : 


pgm.c- it is the source code file of the is generally present in bin 
             directory of the turbo c compiler.if we save our program to other 
             directory then the .c file will be present in that directory rather than bin 

pgm.exe-If there are no errors in pgm.c, then at the time of execution 
              of program it will produces an executable file, which can be      
              executed when needed.

pgm.bak-When a program is about to overwrite an existing file 
               the program may first make a copy of the existing file, 
               with .bak appended to the filename. 
               This common .bak naming scheme makes it possible 
               to retrieve the original contents of the file.

pgm.obj-the obj file contains the machine level code. 

Although we call this process “compiling a program,” what actually happens is more complicated. 

3 Stages of Compilation Stage 

Stage 1: Preprocessing – Performed by a program called the preprocessor
                                    Modifies the source code (in RAM) according to preprocessor directives (preprocessor commands) embedded in the source code – Strips comments and white space from the code – The source code as stored on disk is not modified. 

Stage 2: Compilation Performed by a program called the compiler
                                  It Translates the preprocessor-modified source code into object code (machine code) then Checks for syntax errors and warnings and Saves the object code to a disk file, if instructed to do so (we will not do this). If any compiler errors are received, no object code file will be generated.but An object code file will be generated if only warnings, not errors, are received. 

Stage 3: Linking Combines the program object code with other object code to 
                           produce the executable file. The other object code can come from the Run- Time Library, other libraries, or object files that you have created. and Saves the executable code to a disk file. On the Linux system, that file is called a.out.If any linker errors are received, no executable file will be generated.

1 comment:

  1. Thanks for providing such a amazing information about the internal process of a program. This is really helpful to understand the execution process of any C program, it helps to develop the best programs in future which belongs to real world entity.