* * *

The language of C was developed in the year 1972 by Dennis Ritchie in the AT&T Bells

Laboratories. C is a general-purpose language which has been closely associated with the UNIX operating system for which it was developed. C provides constructs that map efficiently to typical machine instructions, and therefore it has found lasting use in applications that had formerly been coded in assembly language, including operating systems, as well as various application software for computers ranging from supercomputers to embedded systems.

 

Tokens:

The smallest individual unit in a program is known as a Token. C has the following token:

  • Keywords: Words that convey a special meaning to the compiler.
  • Identifiers: Name given by the user for a unit of the program.
  • Literals: Data items that never change their value during the program run.
  • Punctuators: Enhance program’s readability and give proper meaning to statements.
  • Operators: Tokens that trigger some computation or action when applied to variables and other objects in an expression.

 

Fundamental Data Type:

Fundamental data types are those that are not composed of other data types. Five fundamental data types are:

  • int Data type
  • char Data type
  • float Data type
  • double Data type
  • void Data type

Image for Fundamental Data type

A Basic Code:

#include<stdio.h>   //includes the library file named "stdio.h"

int main()          //the execution of the code starts from here

{

  printf("Welcome to IIIT Gwalior");  //prints the given message on the console

                                     //output

  return 0;         //indicates that execution of program is successful

}

 

ASCII( American Standard Code for Information Interchange):

It is a character encoding standard for electronic communication. ASCII codes represent text in computers, telecommunications equipment, and other devices.

The ASCII table is given below:

Image for ASCII table

Operators:

Operators are used to represent operations in C.

The difference in these operators can be shown by the following diagram:

Image for Operators in C

Precedence of operators:

Operator precedence determines the grouping of terms in an expression and decides how an expression is evaluated. Certain operators have higher precedence than others.

The following table lists the precedence order of operators:

Image for Precedence of Operators

The Flow of Control:

Statements are instructions given to the computer to perform any kind of action (like data movement, making decisions, repeating actions).

Depending upon the kind of action, statements may be of following types:

  1. Selection statements:

Statements that take action depending on a condition.

  1. if statement

            The following code explains the functioning of if-statements.

         #include<stdio.h>

         int main()

{



    int marks;

    printf("Enter your marks ");

    scanf("%d",&marks);

    if(marks>=40)

        printf("Pass
");//statement is executed if marks is >=40

    else

        printf("Fail
");//statement is executed if marks is <40

    return 0;

}

 b.   switch statement

            The following code explains working of switch statements.

#include<stdio.h>

int main()

{

int m;

 printf("Enter month ");

 scanf("%d",&m);

 switch(m)//prints the name of the month depending on the number entered

 {

     case 1:printf("January");

         break;

     case 2:printf("February");

         break;

     case 3:printf("March");

         break;

     case 4:printf("April");

         break;

     case 5:printf("May");

         break;

     case 6:printf("June");

         break;

     case 7:printf("July");

         break;

     case 8:printf("August");

         break;

     case 9:printf("September");

         break;

     case 10:printf("October");

         break;

     case 11:printf("November");

         break;

     case 12:printf("December");

         break;

     default: printf("Wrong Input");//printed if none of testcase match

 }



}

 

 

      2)   Iteration statements:

            Allow a set of instructions to be performed repeatedly until certain condition is fulfilled.

  1. for Loop
#include<stdio.h>  //program to find factorial of a number

int main()

{

    int n,i;

    int f=1;

    printf("Enter number ");

    scanf("%d",&n);

    for(i=1;i<=n;i++)

        f=f*i;

    printf("Factorial of %d is %d",n,f);

}

 

      2. while Loop

#include<stdio.h>  //program to find sum of digits

int main()

{

    int x,n,s=0;

    printf("Enter numbers ");

    scanf("%d",&n);

    while(n>0)

    {

        x=n%10;

        s=s+x;

        n=n/10;

    }

 

    printf("sum of digits is %d",s);

 

}

 

      3. do-while Loop

 

Array:

An array is a collection of variables of the same type that are referenced by a common name. The data type of base elements is known as the base type of array. An array is given a name and its elements are referred to by their subscripts or indices.

Arrays are of different types:

  1. One-dimensional arrays: comprised of finite homogeneous elements.
  2. Multi-dimensional arrays: Comprised of elements, each of which is itself an array.

 

The diagram below shows the how an array is stored in memory:

Image for Array

Function:

A function is a named unit of a group of program statements. This unit can be invoked from other parts of the program as and when required.

Function Definition:

return_type function_name( parameter list ) {
   the body of the function
}

Function Prototype:

It is a declaration of the function that tells the program about the type of the value returned by the function and the number and type of each argument.

return_type function_name( parameter list );