Introduction to C
Programming
   Introduction
                  Books
1)The C Programming Language by Brian W.
Kernighan and Dennis M. Ritchie, PHI.
2) Programming in C by E. Balguruswamy, Tata
Mcgraw Hill Publishing.
                What is C?
  C
      A language written by Brian Kernighan
      and Dennis Ritchie. This was to be the
      language that UNIX was written in to
      become the first "portable" language
In recent years C has been used as a general-
purpose language because of its popularity with
programmers.
                    History
In 1972 Dennis Ritchie at Bell Labs writes C and in
1978 the publication of The C Programming Language
by Kernighan & Ritchie caused a revolution in the
computing world
In 1983, the American National Standards Institute
(ANSI) established a committee to provide a modern,
comprehensive definition of C. The resulting definition,
the ANSI standard, or "ANSI C", was completed late
1988.
             Why C Still Useful?
C provides:
  Efficiency, high performance and high quality s/ws
  flexibility and power
  Provide functionality through rich set of function libraries
  Gateway for other professional languages like C → C++ → Java
C is used:
  System software Compilers, Editors, embedded systems
  data compression, graphics and computational geometry, utility
  programs
  Also used in application programs
          Development with C
Four stages
▪ Editing: Writing the source code by using some IDE or editor
▪ Preprocessing or libraries: Already available routines
▪ compiling: translates or converts source to object code for a specific
  platform source code -> object code
▪ linking: resolves external references and produces the executable
  module
Note! Program correctness and robustness are most important
than program efficiency
   Programming languages
Various programming languages
    Some understandable directly by computers
    Others require “translation” steps
 – Machine language
    • Natural language of a particular computer
    • Consists of strings of numbers(1s, 0s)
    • Instruct computer to perform elementary
      operations one at a time
    • Machine dependant
    Programming languages
Assembly Language
– English like abbreviations
– Translators programs called “Assemblers” to convert
  assembly language programs to machine language.
– E.g. add overtime to base pay and store result in gross
  pay
          LOAD          BASEPAY
          ADD           OVERPAY
          STORE         GROSSPAY
    Programming languages
High-level languages
– To speed up programming even further
– Single statements for accomplishing substantial tasks
– Translator programs called “Compilers” to convert
  high-level programs into machine language
– E.g. add overtime to base pay and store result in
  gross pay
          grossPay = basePay + overtimePay
History of C
                     History of C
Evolved from two previous languages
 – BCPL , B
BCPL (Basic Combined Programming Language) used
for writing OS & compilers
B used for creating early versions of UNIX OS
Both were “typeless” languages
C language evolved from B (Dennis Ritchie – Bell labs)
** Typeless – no datatypes. Every data item occupied 1 word in memory.
                 History of C
Hardware independent
Programs portable to most computers
Dialects of C
– Common C
– ANSI C
   • Called American National Standards Institute ANSI C
Case-sensitive
    Structure of C Language program
1 ) Comment line
2) Preprocessor directive
3 ) Global variable declaration
4) main function( )
{
           Local variables;
           Statements;
 User defined function
}
}
               Simple C Program
/* A first C Program*/
#include<stdio.h>
 int main (void)
{
 printf (“Welcome to C Programming language.\n");
return 0;
 }
Output: welcome to c programming language.
Comment line
  It indicates the purpose of the program.
  It is represented as
   /*……………………………..*/
  Comment line is used for increasing the readability of the
  program.
  It is useful in explaining the program and generally used for
  documentation.
Preprocessor Directive:
  #include tells the compiler to include information about the
  standard input/output library.
  It is also used in symbolic constant such as
        #define PI 3.14(value).
   The stdio.h (standard input output header file) contains
  definition & declaration of system defined function such as
  printf( ), scanf( ) etc.
  Generally printf() function used to display and scanf()
  function used to read value
Global Declaration:
  This is the section where variable are declared globally so
  that it can be access by all the functions used in the
  program.
  And it is generally declared outside the function :
main()
 It is the user defined function and every function has one
 main() function from where actually program is started and
 it is encloses within the pair of curly braces.
 The main( ) function can be anywhere in the program but in
 general practice it is placed in the first position.
 The main( ) function return value when it declared by data
 type as
  int main( )
 {
       return 0 ;
 }
  The main function does not return any value when it has void
  (means null/empty) as
      void main()
      {
            printf (“C language”);
      }
Output: C language