Monday, April 28

The C Programming Language

 A course on C Programming : Programming Made Simple & Sweet

C is one of the widely used computer programming language. Though it was developed during 1970's C is still one of the most popular programming language. The main reason for acceptability is, C is very flexible. Moreover, Unix OS and embedded programming is largely based on C.

All credits and due regards  to Dennis Ritchie, for coming up with such a wonderful Programming Language.


1. The C Language:An Introduction

1.1 Features

  •  Currently, the most commonly-used language for embedded systems
  • High-level assembly

  • Very portable: compilers exist for virtually every processor

  • Easy-to-understand compilation

  •  Produces efficient code

  •  Fairly concise

1.2 C History

  • Developed between 1969 and 1973 along with Unix

  • Due mostly to Dennis Ritchie

  •   Designed for systems programming

¨     Operating systems
¨     Utility programs
¨     Compilers
¨     Filters

  •   Evolved from B, which evolved from BCPL

1.3 Pieces of C

 The following are the essential ingredients in a C program.

 Types and Variables
¨     Definitions of data in memory

Expressions
¨     Arithmetic, logical, and assignment operators in an infix notation

Statements
¨     Sequences of conditional, iteration, and branching instructions
  
 Functions
¨     Groups of statements and variables invoked recursively

1.4 Operators in C

Ø       Arithmetic Operators
            + ,  - ,  *,   /  ,  %

Ø       Logical Operators
            && ,   ||  ,  !

Ø       Relational Operators
            <, < = , >, > = , = = , ! =

Ø       Unary Operators                   k = 3
            ++ , - -                                     l = k++     now, l =3 , k = 4.

Ø       Conditional Operators
            ? :
            exp1? exp2: exp3

Ø      Comma operators

            used to link related expressions together

            sum = ( x = 3 , y = 1 , x + y );               Ans: 4

Ø        sizeof Operators

            returns the number of bytes the operand occupies.

            Ex:  sizeof( sum )
                   sizeof (long int)

1.5 Data types

            1.  Primary/ fundamental data type
            2.  User defined data type
            3.  Derived data types

1.5.1 Primary/ fundamental data type

            There are 5 of them -  integer, character, floating point, double and void.

            Integer  -> short int, int , long int (in both signed and unsigned form.)

            Float(32 bits),  double(64 bits),  long double(80 bits).

Example variable  declaration:

         int a;
         int b;
        int x, y;
       float t;
       float p, q;

1.5.2 User defined data type

       i)  typedef      used to declare variables that would represent an existing variable.

       Ex:   typedef  int value;
            now,
               value v1, v2;

      ii) Enumurated data types
            to declare variable that can have one of the values enclosed within the braces.

            Ex:         enum car  {  ac, nonac };
                         car   zen, santro, spark ;         
 
 Thus, each variable here could be assigned any one of the constants from ac nonac. the enumeration constants will automatically represent integer values as: ac  0  and  nonac   1.

1.5.3 A Simple Program in C

Here is our first program. This will display the message ' Hello How are You' on the screen.

#include <stdio.h>
void main()
{
  printf(“Hello How are You\n”);
}

Fig.1 below marks the important elements in the program.

Question2.

Write a program to print your residential address?
==========================================================================

Visit the Pages listed on right side for more. 
No parts from this site shall be copied or reproduced without prior permission.
All questions or doubts in C may posted as comments for answering.