C Language Full Details Notes

C Language Full Details Notes.

∎ Why C language is so important?

  ➤ worth to know about c language

    - oracle is written in c

    - core libraries of android are written in c

    - MySQL is written in c

    - Almost every device driver is written in c

    - Major part of web browser is written in c

    - Unix operating system is developed in c

    - c is the worlds most popular programming language

For students

For students

    - C is important to build programming skills

    - C covers basic features of all programming language.

    - Campus recruitment process

    - C is the most popular language for hardware dependent programming

∎ History of C language.

   - Developer of BCPL ( Basic combined programming language) (Martin Richards)

     develop in 1966.

    - Developer of B language (Ken Thompson) develop in 1969.

      Also developer of Unix Operating system. 

     He also developed first mater level chess called Belle in 1980.

    - Developer of C language in 1972 (Dennis Richie)

      AT AT & T's Bell Labs, USA

    - Co-developer of unix operating system.

∎ What is 0 and 1.

    - There is nothing like 0 and 1 in computer. there is no physical significance of 0 and 1

    - Any information can encoded as a sequence of 0 and 1

∎ Program and process.

    - Set of sequential instruction is called program.

     - Active state of a program is called process.

∎ Constant

    - Any information is constant

    - Data=information=constant

∎ Type of Constants

    (i) Primary Constants

        (i) integer

        (ii) Real

        (iii) Character

    (ii) Secondary Constants

        (i) Array

        (ii) String

        (iii) Pointer

        (iv) Union

        (v) Structure

        (vi) Enumerator

∎ Variables

    - Variables are the name of memory locations where we store data.

∎ Rules for constructing variable names in C

    - Variable name is any combination of alphabet, digit and underscore.

    - (A-Z) the first character must be a letter

    - Space is not allowed between names of identifiers

    - Special symbols are not allowed (&*^#$@)

    - Not allow white space

    - A valid variable name cannot start with digit

    - Underscores_can be used

    - the reserve word are not allowed (int, float, char etc.)

∎ Keywords

    - predefined word

    - reserved word

    - There are 32 Keywords in C language

∎ List of Keywords

    auto    double    goto    signed    unsigned

    Break    default    if    sizeof    void

    case    enum    int     static    volatile

    char    else    long    struct    while

    const    extern    register    switch

    do    for    return    typedef

    continue    float    short    union

∎ Instruction

    - program statements are called instruction.

    - instruction are commands

∎ Type of instruction

    - data type declaration instruction

    -input output instruction

    - arithmetic instruction

    - control instruction

∎ Data Type

    - int

    - char

    - float

    - double

    - void

    - it is also known as primitive data type

∎ Size of Data Type in C

TypeRangeSize (in bytes)
unsigned char0 to 2551
signed char or char-128 to +1271
unsigned int0 to 655352
signed int or int-32,768 to +327672
unsigned short int0 to 655352
signed short int or short int-32,768 to +327672
unsigned long int0 to +4,294,967,2954
signed long int or long int-2,147,483,648 to +2,147,483,6474
long double3.4E-4932 to 1.1E+493210
double1.7E-308 to 1.7E+3088
float3.4E-38 to 3.4E+384

∎ Standard input/output Device

    - Keyboard is standard input device

     - Monitor is standard output device

∎ printf()

    - printf() is not a keyword

    - printf() is a predefined function

    - Two type of messages

        - printing text as it is

        - printing value of expression or value of variable.

∎ First program in c language

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

        printf("Hello India");

        getch();

    }

____________________________________

#include <stdio.h>

#include <conio.h>

    void main ()

{

    clrscr(); // to clear screen

    printf("Hemant");

    printf("\h kumar");

    getch();

}

#include<stdio.h>

#inclode<conio.h>

    void main()

{

        clrscr();

        gotoxy(40,13);

        printf("Hemant \h kumar");

        getch();

}

____________________________________

#include<stdio.h>

#inclode<conio.h>

    void main()

{

        int a=4,b=5;

        clrescr();

        printf("%d%d",a,b);

        getch();

}


/*

    Format specifier

    %d int

    %f float

    %c char

    %if double

*/


#include<stdio.h>

#include<conio.h>

        void main()

{

        int a=4, b=5;

        clrscr();

        printf("sum of %d and %d is %d",a,b,a+b);

        getch();

}

_______________________________________

scanf()

   ðŸ”˜ scanf() is not a keyword

   ðŸ”˜ scanf() is a predefined function 

   ðŸ”˜ scanf("format specifier",variable address);

  

 #include<stdio.h>

  #include<conio.h>

        void main()

{

        int x;

        Scanf("%d",&x);

        printf("square of % is %d",x,x*x);

        getch();

}


#include<stdio.h>

#include<conio.h>

        void main()

{

        int x;

        clrscr();

        printf("enter a number :=");

        Scanf("%d",&x);

        printf("square of %d is %d",x,x*x);

        getch();

}

ASCII Codes :-

🔘 ASCII stand for American standard code for Information Interchange

🔘 ASCII Code is the numerical representation of a character such as 'a' or '@' or an action of some sort.


ASCII is an old encoding :-

🔘 ASCII was developed a long time ago and now used the non - printing Characters are rarely used for their original purpose.

🔘 ASCII was actually designed for use with teletypes.

🔘 A teleprinter (teletypewriter Teletype or TTY) is an electromechanical typewriter that can be used to send and received type massages form point to point and point - to - multipoint over various types of communications channels.    

Arithmetic Instruction :- 

An instruction which is used to manipulate data using operators, is known as Arithmetic instructions.          

Operator Groups :-

🔘 Unary operators 

🔘 Arithmetic operators 

🔘 Bitwise operators

🔘 Relational operators

🔘 Logical operators

🔘 Conditional operators

🔘 Assignment operators

Unary operators :- 

+ , - , ++ , -- , size of ()

++ (increment operator)

-- (decrement operator)


#include<stdio.h>

#include<conio.h>

        void main()

{

        int x = 3;

        clrscr();

        x++;  // x = x +1 

        printf("%d", x);

        getch ();

}

____________________

#include<stdio.h>

#include<conio.h>

        void main();

{

        int  x = 3

        clrscr();

        x++ // post increment

        printf("%d",x);

        ++x; // pre increment

        printf ("%d",x);

        getch ();

}

__________________

#include<stdio.h>

#include<conio.h>

        void main ();

{

        int x = 3 , y ;

        clrscr();

        y = x ++ ;

        printf("%d%d" , X , y);

        getch ();

}

sizeof ():-

sizeof (data type)

sizeof (variable)

sizeof (constant)


#include<stdio.h>

#include<conio.h>

        void main ();

{

        int x;

        clrscr ();

        x = sizeof(int);

        printf("%d" , x);

        getch ();

}

_____________________

#include<stdio.h>

#include<conio.h>

        void main ();

{

        int    x , y ,z;

        x = sizeof(34);

        y = sizeof(3.56);

        z = sizeof('a');

        printf (" %d %d %d " , x , y , z);

        getch ();

}

Modulo operator :- 

    5 % 2  =  1

    -5 % 2 =  -1

    5 % -2 = 1

    -5 % -2 = -1

Bitwise Not operator (~) :- 

Bitwise

Unary

Bitwise & Operator :-

    0 & 0 = 0

    0 & 1 = 0

    1 & 0 = 0

    1 & 1 = 1

example :-

    int x;

    x = 23 & 56;

    

    23 = 0000  0000  0001  0111

    56 = 0000  0000  0011  1000

    16 = 0000  0000  0001  0000


Bitwise | (or) operator 

 0  |  0  = 0

 0  |  1  =  1

 1  |  0  =  1 

1  |  1  =  1

example :-

        int   x ;

        x = 23 |  56 ;

23 = 0000  0000  0001  0111

56 = 0000  0000  0011  1000

63 = 0000  0000  0011  1111


Bitwise   ^   (XOR) Operator  :-

 0   ^   0   =   0

 0   ^   1   =   1

 1   ^   0   =   1

 1   ^   0   =   0

example :-

            int   x ;

            x = 23  ^  56;

23 = 0000  0000  0001  0111

56 = 0000  0000  0011  1000

47 = 0000  0000  0010  1111

 

Right shift operator :- (>>)

    int  x ;

    x = 56 >> 2;

56 = 0000  0000  0011  1000 

14 = 0000  0000  0000  1110

Left shift (<<) operator :-

    int  x;

    x = 56 << 3;               

  56 = 0000 0000 0011 1000

448 = 0000 0001 1100 0000

Relational operators :-

    < , > , < = , > = 

    = = , ! = 

Remember :-

🔘 Relational operator always fields result either  0 or 1 

🔘 Every non - zero value is True and zero is false 

🔘 True is 1 and false is 0


#include<stdio.h>

#include<conio.h>

        void main ();

{

        int  x ;

        clrscr();

        x = 3 > 4;

        printf ("%d" , x);

        getch ();

}

____________________

#include<stdio.h>

#include<conio.h>

        void main ();

{

        int  x ;

        clrscr ();

        x = 3<=4 ;

        printf("%d", x);

        getch ();

}

_____________________

#include<stdio.h>

#include<conio.h>

        void main ();

{

        int   x; 

        clrscr();

        x = 4!= ;

        printf("%d", x);

        getch ();

}


#include<stdio.h>

#include<conio.h>

        void main ();

{

        int  x;

        clrscr();

        x = 5 > 4 > 3 ;

        printf(' %d ", x);

        getch ();

}                                                

Logical operator  :-

    NOT            !

    AND          & &

    OR            |  |

NOT Operator

🔘 It is also unary operator 

🔘 Priority level as same as of unary operators

🔘 It inverts the truth value of statement

!T  = F

!F  = T


#include<stdio.h>

#include<conio.h>

        void main ();

{

        int   y , x = 5 ;

        clrscr();

        y = !x > 4;

        printf("%d " , Y);

        getch ();

}

__________________       

#include<stdio.h>

#include<conio.h>

        void main ();

{

        int   y , x = 5 ;

        clrscr();

        y = x > 4 && x < 10;

        printf("%d", y );

        getch ();

}    


&&



#include<stdio.h>

#include<conio.h>

        void main ();

{

        int  y , x = 5

        clrscr ();

        y = x < 4  ||  x < 10  ;

        printf(' %d ", y);

        getch ();

}


|  |



Conditional operator ( ? : ) :-

    -  Ternary operator 

    - Conditional operator 

Syntax :-

               exp1 ? exp2 : exp3

x > 4 ? printf("A") : printf("B");

            _________   ________

                True              False                          

#include<stdio.h>

#include<conio.h>

        void main ();

{

        int  a , b ;

      printf("enter two number")

      Scanf("%d %d ". & a, & b );

      printf(" Greatest number is %d " , a > b ? a : b );

        getch ();

}


Compound Assignment operator :-

    + = , - = , * = , / = , % = , & = , | = , ^ =

        int   x = 5;

        x  +  =  4;  // x = x + 4

        x * = 3 ; // x = x * 3

        x % = 2 // x = x % 2


Control Instructions :-

    Decision Control Instruction 

    Iterative control Instruction

    Switch Case Control Instruction

    go to Control Instruction


Decision Control Instruction 

    If 

    If else 

    Conditional operator (?:)

*Write a program to check wether a number is positive or not *

    #include<stdio.h>

    #include<conio.h>

        void main ();

{

        int  x;

        clrscr ();

        printf("enter a number");

        Scanf("%d " , & x );

        if ( x > 0)

{

        printf("positive number");

}    

    if (x< = 0 )

{

    printf(" Non positive Number ");

}

    getch ();

}

 

If else :-

    syntex :-

            if (condition)

            {

                line 1 ;

                line 2 ;

                 -------

            }

    else

        {

        line 1;

        line 2 ;

        --------

        }


#include<stdio.h>

#include<conio.h>

        void main ();

{

        int  x ;

        clrscr();

        printf("enter a number");

        Scanf("%d" , & x );

        if ( x > 0 )

{

        printf("positive number ");

}

    else

{

    print ("Non positive")

}        

    getch ();

}

__________________

#include<stdio.h>

#include<conio.h>

        void main ();

{

        int  x;

        clrscr ();

        printf('"enter a number" );

        Scanf ("%d " , & x);

        if (x > 0 )

                printf("positive");

        else

                printf("Non Positive");

         getch ();

}


Conditional operator (?;)

    Syntex :-

                Condition ? Statement 1 : Statement 2;


#include<stdio.h>

#include<conio.h>

        void main ();

{

        int  x;

        clrscr ();

        printf("enter a number");

        Scanf("%d " , & x );

        x > 0 ? printf("positive"); printf("Non positive");

        getch ();

}

Selective Assignment :-

    x = a > b ? a : b ;


#include<stdio.h>

#include<conio.h>

        void main ();

{

        int  x , y , max;

        clrscr ();

        printf("enter tow numbers");

        Scanf("%d  %d " , & x , & y );

        max = x > y ? X : y ;

        x > 0 ? printf("greater number is %d ",max );

        getch ();

}

 Nested if else:-

    if (some condition)                :    if (condition)

{                                                :    }

    if (some condition)                :    

    {                                            :    }

                                                  :    else

}                                                :    {

else                                            :    if (condition)

{                                                :    {

}                                                :

}                                                :    }

else                                            :    else

{                                                :    {

                                                  :    }

}                                                :    }


/ / Largest among 3 variables using nested if 

    #include<stdio.h>

#include<conio.h>

        void main ();

{

        int  a ,b , c;

        printf("enter three number");

        Scanf("%d %d %d  " , & a , & b , & c );

        if (a>b)

        {

                    if (a > c )

                        printf("%d " , a );

                    else 

                    printf("%d " , c);

}

else

{

            if ( b > c)

                    printf("%d " , b);

                    else

                    printf("%d" , c);

}

       getch ();

}


If else ladder:-

    syentex :-

    if  ( )

            Statement ;

    else if ( )

            Statement ;

    else if ( )

            Statement ;

    else if ( )

            Statement ;


#include<stdio.h>

#include<conio.h>

        void main ();

{

        int   marks;

        printf("enter your marks");

        Scanf("%d " , & marks);

        x > 0 ? printf("positive"); printf("Non positive");

        else if (marks > 90 )

                printf("Grade - A");

        else if (marks >80)

                printf("Grade - B");

        else if (marks >70)

                printf("Grade- C");

        else 

                printf("Grade - D ");

        getch ();

}


                                                        Loop

Iterative Control Instructions :-

    While

    do while

    for


#include<stdio.h>

#include<conio.h>

        void main ();

{

        int  i = 1 ; / / Initialization

        clrscr ();

        while (i < = 5 ) / / Conditional

{

        printf("STATEMENT \ h");

        i + + ;   / / Flow

        }

        getch ();

}


*Syntex compariso :-

    main ( )

{

        int i =1

        while (i < = 5)

{   

        printf("hemant");

        i + + ;

}

    getch ();

}

---------------------------------------------------------------------------------------------------------------

main ( )

{

        int i =1

       do

{   

        printf("hemant");

        i + + ;

        while (i < = 5)

    getch ();

}


----------------------------------------------------------------------------------------------------------------


main ( )

{

        int     i

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

{   

        printf("hemant");

}

    getch ();

}


*Break :-

    The keyword break can be use used is loop body or in switch body.

    The purpose if break is to terminate loops execution immediately as it encounters.

example :-

#include<stdio.h>

#include<conio.h>

        void main ();

{

        int   i = 1 , x ;

        {

            printf("enter a number");

            Scanf("%d  %d " , & x);

          if ( x > 0 )

                    break;

        i + + ;

}

        i = 6 ? printf("ends normally ; printf("appliod braek");

        getch ();

}

                                                    Switch Control

*Syntax :-

Switch (expreession)

{

    Case constant : Code ;

    Case constant : Code ;

    Case constant : Code ;

    Case constant : Code ;

        default : code ;

}


*example :-

    Write a menu driven program with the following options;

1. Addition 

2. Odd - even

3. Printing first natural N numbers

4. exit

    #include<stdio.h>

    #include<conio.h>

        void main ()

{

        int choice ,a ,b ,s 

while (1)-

                clrscr ();

                printf(" \n 1. Addition");

                printf(" \n 2. Odd - even")

                printf(" \n 3. printing N number");

                printf(" \n 4. exit");

                printf("\n\n enter ypur choice");

                Scanf(%d ". & chioce );

Switch (chioce)

{

Case 1 :

            printf("Enter tow numbers");

            Scanf("%d %d ", & a , & b );

            s = a + b ;

            printf("in sum is %d", S);

            break;

Case 2:

            printf("enter a number");

            scanf("%d ", & a);

            if (a % 2 = = 0)

                                    printf("even number");

                            else

                                   printf("odd number");

                            break;

Case 3 :

            printf("enter a number");

            scanf("%d" , & a );

            for ( b=1 ; b < =a ; b + + )

                print ("%d" , b);

            break;

Case 4 : exit (0);

            default ;

                        printf("Invalid choice");

}

    getch();

}


*What is function ( )?

    Piece if cide to accomplish certain poeration .

    It has a name for identification 

    They area if two types 

        - Predefined function 

        - user defined function 


*Remember :-

    Program muat have at least one function 

    Function names must be unique 

    Function is an operation , Once defined can be used many times .

   One function is the program must be main

   Function consumes memory only when it is invoked and released from RAM as soon as it finishes its     job.


*Benefits of function :-

    Modularization 

    easy to read 

    easy to debug

    easy to modify

    Avoids rewriting if sane code over and over

    Better memory utilization


*Ways to define a function 

    Takes Nothing , Returns Nothing 

    Takes Something , Returns Nothing 

    Takes Nothing , Returns Something

    Takes Something , Returns Something


/  / Takes Nothing , Return nothing

    #include<stdio.h>

    #include<conio.h>

        void main ()

{

        clrscr ( );

        add ( );

        getch ( );

}

    void add ( )

{

        int  a ,b , c;

        printf("enter tow numbers");

        Scanf("%d %d ", & a , & b );

        c = a  +  b;

        printf("sum is old %d " , C);

}


/  / Takes Something Return Nothing

    #include "stdio.h"

    #include "conio.h"

        void add (int , int );

        void main()

{

        int  x , y ;

/ / void add (int , int ); यहाँ भी use कर सकते है आप   

    clrscr();

        print("enter tow numbers");

        Scanf("%D ", & x , & y);

        add ( x , y ) ; | | Actual Argument /call by value 

        getch();

}

    void add ( int a , int b ) / / formula Arguments 

{

        int  c ;

        c  =  a+ b

        printf("sun is %d " , C );

}


/ / Takes Nothing Returns Something

    #include<stdio.h>

    #include<conio.h>

        int add (void);

        void main ( )

{

        int  s ;

        clrscr ( ) ;

        s = add ( ) ;

        printf("sum is %d " , S);

            getch ( );

}

        int add ( )

{

        int  a , b , c ;

        printf("enter tow numbers");

        Scanf( "%d %d " , & a < & b );

        c = A + b ;

        return (c);

}


/ / Takes something Returns Something

    #include "Stdio.h"

    #include "conio.h"

            int add ( int  , int );

            void main ( )

{            

            int   s , x , y ;

            clrscr ( );

            printf("enter tow numbers");

            Scanf(" %d %d " , & x , & y );

            s = add ( x , y );

            printf("sum is %d " , S);

            getch ( ) ;

}

            int add (int a , int b)

        {

            int   c ;

                    c = a + b;

                return ( c) ;

}


*Recursion :-

    Function calling itself is called Recursion 

*Arrays :-

    Array is also linear collection of similar elements 

    Array is also known as subscript variable 

    Array is a group of variable 

            0    1    2    3    4    5    6    7    8    9

#include<stido.h>

#include<conio.h>

    void maik();

{

        int  a[ 10 ] , i sum = 0 ;

        float avg;

        clrscr ( ) :

        printf("enter 10 numbers");

        for ( i = 0 ; i < = 9 ; i + + )

            Scanf(" %d " , & a [ i ]);

        for ( i = 0 ; i < = 9 ; i + + )

        avg = sum / 100;

        printf("Average is % f " ; avg);

        getch ( ) ;

}

*Declaration of Arrays :-

    int  a [  ] ; error 

    int  a [ 5 ] ; 

    int  a [ 5 ] = { 9 , 6 , 8 , 0 , 2};

    int  a [  ] = { 9 , 6 , 8 , 0 , 2 };


*Two Dimensional Arrays :-

    int  b [ 2 ]  [ 3 ] ;





#include<stdio.h>

#include< conio.h>

        void main ()

{

        int A [ 3 ] [ 3 ] , B [ 3 ] [ 3 ] , c [ 3 ] [ 3 ] , i , j ;

        clrscr ();
        print("enter 9 number for first matrix");
        for (i = 0 , i < = 2 ; i + + )
            for ( j = 0 , j < = 2 ; j + + )
                    Scanf("%d " , & A [i ] [ j ] );
        printf("enter 9 number for second matrix");
        for (i = 0 , i < = 2 ; i + + )
            for ( j = 0 , j < = 2 ; j + + )
                    Scanf("%d " , & b [i ] [ j ] );
            for ( i = 0 ; i < = 2 ; i + + )
}
            for ( j = 0 ; j < = 2 :  j + + )
{
                C [i] [j] = A [ i ] [ j ] + B [ i ] [ j ] ;
                 printf(" %d " , C [ i ] [ j ] );
}
            printf("\ n ");
}
        getch ( ) ;
}

*String :-
    Sequence of Characters terminated at null Character.
    ASCIT Code of null Charatcter is 0 ( Zero)

#include<stdio.h>
#include<conio.h>
    void main ( )
{
    char s [ 10 ] = {' H' , ' E ' , ' M ' ,  'A ' ,  ' N '  , ' T ' , ' 10}
    int  i ;
    clrscr ( ) ;
    for ( i = o ; i < = 6 ; i + + )
        print ("%c" , S [ i ] ) ;
     getch ( ) ;
}

#include<stdio.h>
#include<conio.h>
    void main ( ) ;
{
    char s [ 10 ] = {' H' , ' E ' , ' M ' ,  'A ' ,  ' N '  , ' T ' , ' 10}
    int i i 
    clrscr ( ) ;
    for ( i = 0 ; S [ i ] ! = ' \ 0 ' ; i + + )
        printf ("%C " , S [ i ] );
        getch ( );
}

#include "stdio.h"
#include "conio.h"
    void main ( )
{
        char S [ 10 ] = { 'S' , ' A ' , ' M ' , ' E ' , ' \0 ' }/ " SAME ";
        int    i ; 
        clrscr ();
        printf("%S' , S);
                    or
        puts ( S );
        getch ();
}

#include"stdio.h"
#include"conio.h"
    void main ( )
    
        char  S [ 20 ]
        int i ;
        clrscr ( ) ;
        printf("enter your name ");
        gets ( S ) ;
        puts ( 65[0] ); / puts ( S );
        getch ();
}


*String related functions :-
    Strlen ( )
    Strrev ( )
    Strlwr ( )
    Strupr ( )
    Strcpy ( )
    Strcmp ( )
    Strcat   ( )

    / / program to calculate length of string using strlen ( ) function in C

#include<stdio.h>
#include<conio.h>
#include<string.h>
    void main ( )
{     
        char  S [ 20 ]
        int l ; 
        clrscr ( ) ;
        printf("enter your name ");
        gets ( S ) ;
        l = strlen ( S );
        printf("length of % s  is % d " , s , l );
        getch ()
}

/*Program to reverse a string using strrev ( ) function in C */ 

#include"stdio.h"
#include"conio.h"
#include"string.h"
    void main ( )
{     
        char  S [ 20 ]
        clrscr ( ) ;
        printf("enter your name ");
        gets ( S ) ;
        strrev ( s);
        printf("%s " , s);
       getch ();
}
        
/ * Program to transform a string into its uppercase without using strupr ( ) function in C * /

#include"stdio.h"
#include"conio.h"
#include"string.h"
    void main ( )
{     
        char  S [ 20 ]
        int i ; 
        clrscr ( ) ;
        printf("enter your name ");
        gets ( str ) ;
        for ( i = 0 ; str [ i ] ; i + + )
{
        if ( str [ i ] > = ' a ' & & str [ i ] < = ' Z ' )
                str [ i ] = str [ i ] - 32;
}
        printf(" %s " , str);
}

*Basic of pointers :-
    int     x = 5 ;
                
                                x        Name of Memory Block Variable
                                5        Content on Memory block
                            2048      Address of Memory Block
main ( )
{
    int  x = 5 ;
    printf("%d" , x);
    printf(" \n %d " , &x);

*Address of Operator : - 
    & is known as address if operator 
    it id an unary operator 
    Operand must be the name of variable 
    & Operator gives address number of variable 
    & is also known as referencing operator 

* indirection Operator :-
    is indirection operator 
    it is also know as dereferencing operator
    it is an unary operator 
    it takes address as an argument
    * returns the content / container
    whose address is its argument.

*Example : -
    
        main ( )
        {                                                                    output
            int    x = 5 ;                                                5
            printf(" %d" , x);                                        2048
            printf("\n %d" , & x );                                5
            printf("\n %d" , *&x);
}

*Question :- 
    int     x = 5                                             x
    & x = 7 ;                                                5
                                                            2048

We can't store anything in & x as & x is not a variable it is the way to represent of block x

*But.......:-                                                x                    j
    int     x=5 ;                                            5                    2048
    int *j; J = & x ;                                    2048                3000

    We can store address in another variable 
    But j has to be declared before use.

* Pointer :-
    pointer is a variable that contains address if another variable.
    Pointer always consumes 2 bytes in memory 
*Question :-
    main ( )
{
        int      x = 5 , *j;
        j = & x :
        printf(" %d %u\n " , x , j );
        printf(" % d % u " , * j , & x );
}

                5            2048
                5            2048
                2048


                x                    j
                5                    2048
                2048              3000
*Pointer's Arithmetic :-
    We cannot add , multiply or divide tow addresses (subtraction is possible)
    We cannot multiply an integer to an address and similarly we cannot divide an address with an integer value.

*Example :-
    write a function to swap two integers.
   #include<stdio.h>
   #include<conio.h>
        voide main ( )
}
        int  a , b ;
        clrscr ( );
        printf("enter tow numbers");
        scanf(" %d %d " , & a , & b );
        swap ( &a , &b );  // call by refrence;
        printf(" a = %d  b = %d " , a , b );
        getch ( );
}

        void  swap ( int * x , int * y )
{

        int   t ;
        t = * * ;
        * x = t ;
        * y = t ;
}

*Call by reference :- 
    Call by reference is same as call by address .
   
     When formula arguments are pointer variable , it is call by reference .
     
     Reference means address .


            void input (int   * p)
{
                int i ;
                for ( i = 0 ; i < = 4 ; i + + )
                    scanf(" %d " , P + i );
}
    void display (int   *p)
{
    int i ;
    for ( i = 0 ; i <  = 4 ; i + + )
        printf(" %d " ,  * ( p + i ) ;
}
void sort ( int   * p)
{
        int round , t , i ;
        for ( round = 1 ; round < = 4 ; round + +
        {
            for ( i = 0 ; i < = 4 - round ; i + + )
                if ( * ( p + i ) > * ( p + i + 1 ) )
                {
                    t = * ( p + i ) ; // a [ i ]   * ( p + i )
                    * ( p + i ) = * ( p + i + 1 );
                    * ( p + i + 1 ) = t;
                 }
          }
}

        void main ( ) 
        {
            int   a [ 5 ] ;
            clrscr ( ) ;
            input ( a ) ; 
            display ( a ) ;
            sort ( a ) ;
            display ( a ) ;
        getch ( );
        }

Write a function to calculate length of a string.
    
    #include<stdio.h>
    #include<conio.h>
        
            int length (char * );
            char * reverse ( char * );
    void main ( )
{
    clrscr ( ) ;            
    printf("%d "  , length (" computer"));
    printf(" \n %s ", reverse ("computer"));
        getch ( );
}    
    char * reverse ( char     *p)
{
        int    l , i ;
        char    t ;
        for ( i =0 ; * (p+l) ; = ' \ o ' ; l + + );
            for ( i = 0 ; i < l/2 ; i + + )
                {
                    t = * ( p + i ) ;
                    * ( p + i ) = * ( p + l - 1 - i ) :
                    * ( p + l - 1 - i ) = t ;
                }
                retiurn ( p );
        int length ( char   * p )
{
        int   i ;
        for ( i = 0 ; * ( p + i ) 1 = ' \ 0 ' ; i + + ) ;
        return ( i ) ;
}

/* function to reverse a string */
    

     #include<stdio.h>
    #include<conio.h>
        
        char *   reverse (char * );
        void main ( )
    {
            clrscr ( );
            printf("%s " , reverse ("computer"));
            getch ( );
    }
    chart *  reverse (char * )
{
            int     l , i ;
            char ch ;
            for ( l = 0 ; * ( p + l ) ! = ' \ 0 ' ; l + +);
                    for ( i = 0 ; i < l/2 ; i + + )
                    {
                        ch = * ( p + i );
                        * ( p + i )= * ( p + l - 1 - i );
                        * ( p + l - 1 - i ) = ch ;
                    }
                return ( p );
}


                                                            *Structure*

* What is structure ?
    Structure is a way to group variable 
    Structure is a collection of dissimilar elements
    Defining structure means creating new data type.

*Defining structure :-
    struct tag
    {
            / / Variable declaration here 
    };

*Memory Consumption :-
    No memory is consumed for definition of structure .
#include<stdio.h>
#include<conio.h>

        struct date
        {
                int d , m , y ;
        }
        void main ( )
        {
                struct date today , d1;
                today . d = 26 ;
                today . m = 07 ;
                today . y = 2022 ;
                d 1 = today ;
                clrscr ( ) ;
                printf("emter today's date ");
                scanf(" %d " / %d / %d " , & d 1 . d & 1 . m , & d 1 . y );
                printf(" date : %d / %d / " , d 1 .d , d 1 , m , d 1 , y );
                    getch ( ) ;
        }


#include<stdio.h>
#include<conio.h>
            struct book
            {
                    int  bookid;
                    char title [20]
                    float price ;
            };
            struct book input ( )
            {
                struct book b ;
                printf("enter bookid , titlt , and price ");
                scanf(" %d " , & b . bookid);
                fflush (stdin);
                gets ( b. title );
                scanf(" %f " , & b . price ) ;
                return ( b );
}
    void display ( struct book b )
{
        printf("\n %d  %s  %f  ", b.bookid , b. title , b. price);
}
    oid main ( )
{
        struct book b 1 ;
        clrscr ( ) ;
        b 1 = input ( ):
        display ( b 1 ) ;
            getch ( );
}

*Dynamic Memory Allocation :-
    SMA : Static Memory Allocation
    DMA : Dynamic memory Allocation 

*What is union?
    Union is similar to structure , except it allows you to define variables that share storage space

    Defining union means creating new data type 

            struct item                                 union item
            {                                                {
                int    x;                                        int    x;
                float    y;                                    float    y;
                char    z;                                    char    z;
            };                                                };
            struct item i 1 ;                          union iem i 1 ;






Union item 
        int     x ;   float     y;    char    z ;
};
void main ( )
{
        union item i 1 ;
        clrscr ( ) ;
        i 1 . x = 5 ;
        printf(" \ n x = %d " , i 1 . x );
        i 1 . y = 3.5 ;
        printf(" \ n x = % d " , i 1 . x);
        i 1 . z = ' a ' ;
        printf("\ z = % c ' , i 1 . z ) ;
        getch () ;
}


*How to access?
    Union members are accessed in the same manner as we access structure member .

*What is enumerator ?
    it gives an opportunity to invent own data type and define what values the variable of this data type         can take.

enum month
{
        jan , feb , mar , apr , may , jun , jul , aug , sep , oct , nov , dec
};


* Creating variable of enumerators:-
    enum month
{
        jan , feb , mar , apr , may , jun , jul , aug , sep , oct , nov , dec
};
    main ()
    {
            enum month m1 , m2 , m3;
    };


internally , compiler treats the enumerators as integers.

each value in the list of permissible values corresponds to an integer , starting with 0 in the example , jan is stored 0 , feb is stored as 1 ........ , dec is stored as 11

We can initilize enumerators with different integer values 
        ex :- jan = 1 , feb .....

enum boolean is even (int    x)
{
        if ( x %2 = = 0)
                return ( false);
}
    void main ()
{
    int     n ;
    enum boolen result ;
    clrscr ();
    printf("enter a number");
    scanf(" %d " , &n);
    result = is even (n);
    if ( result = = true )
        printf("even number");
            eles 
            printf("old number");
        getch ();
}


*What is typedef ?
    type is a keyword

    We can use typedef to give nw name to a type

    typedef int LENGTH;

    Now you can use LENGTH  as a data type which is just same as int LENGTH x ,x ;


*typedef 
    By convention , uppercase letter are used for these definitions to remind the user that type name is         really a symbolic abbreviation , but you can use lowercase

    typedef int length;


*What is pre-processor?
    Pre - processor is a program which performs before the compilation .

    Pre - processor only notices # started statements

    # is called pre - processor directive

    each preprocessing directive must be on its own line.

    The word after # is called pre - processor command.


* # include
    include os one of the mast popular pre - processor dommand 

    it can be used include any five content to your source file 

    #include<file_name>
    #include"file_name"

*Remember :-
    #include<c;\myprog\clang\list.h> is wrong

    #include"c:\myprog\clang\list.h" s correct


*Inclusion of another source file 

    You can write your source code is multiple . c files

    You can include all these source files in the same way as you include header files .


* # define :-
    The #define directive defines an identifier and a character sequence ( a set of characters ) that will be substituted for the identifier each time it is encountered in the source file.


*Syntax :-
    The identifier is referred to as a macro name and the replacement process as macro replacement             process as macro replacement.

#define macro - name char - sequence 


*Example:-

#define PI 3.14 
#define MSG "hello"

#include<stdio.h>
#include"conio.h"
        #define product ( a , b ) a * b
    void main ()
{
        printf("product of 3 and 4 is %d" , product (3 , 4 ) );
        getch ( ) ;
}


*#undef :-
    it is used to undefined macros 
    example 
        #define close 0
        ........
        ........

    #undef close
            ........
            ........


    



          
    
    


(Working in Process).........................