Baadshah Of Programming

C Programming Tutorial


The C programming language is a general-purpose , high-level language (generally denoted as structured language).C programming language was at first developed by Dennis M. Ritchi.

C is one of the most commonly used programming language . it is simple and efficient therefore it become best among all it is used in all extents of application , mainly in the software development.

Many software's & application as well as the compilers for other programming languages are written in C also Operating Systems like Unix , DOS and Windows are written in c.

C has many powers , it is simple , stretchy and portable , and it can control System Hardware easily. it is also one of the few language to have an international standard , ANSI C

  • Fast , Powerful & Efficient
  • Easy To Learn
  • It Is Portable
  • Mid-Level Language
  • Widely Accepted Language
  • Supports Modular Programming Style
  • Useful For All Aplication
  • Easy To Connect With System Device

  • #include<stdio.h> void main()
    {
    printf("Hello World");
    }

    -- Discription --
    #include<stdio.h> This Is Preprocessor Command Which tells compiler to include stdio.h file.

    main()
    C Programs consist of one or more function , there must be one and only one function called main.

    {}
    This is Scope of body.

    Usually Variable Are Declared Before Use Either At The Start Of A Block Of Code After The Opening { and Befor Any Other Statement Or Outside a Function

    We Can Use Any Combination Of Latters And Number For Variable And Function Names but It Must Start With Latter Or Underscore(_).

    There Are Hello And hello Both Are Different Variable.

    -- Variable Declaration --
    int a;
    float b;
    -- Variable Type --
  • Local Variable
  • Global variable

  • There are many 'built-in' data type in c

    - short int -128 to 127 (1 byte)
    - unsigned short int 0 to 255 (1 byte)
    - char 0 to 255 (1 byte)
    - unsigned char 0 to 255 (1 byte)
    - signed char -128 to 127 (1 byte)
    - int -32,768 to 32,767 (2 bytr)
    - unsigned int 0 to 65,535 (2 byte)
    - long int -2,147,483,648 to 2,147,483,647 (4 byte)
    - float (4 byte)
    - double (8 byte)
    - long double (10 byte)

    An Operator Is Syambol. Compiler Identifiers Operator And Performs Specific Mathematical Or Logical Operation.C Provides Following Operators.

    Arithmetic Operators
    * , / , % , + , -
    Increment Decrement Operators
    ++ , --
    Relational Operators
    == , != , >< , >= , <=
    Logical Operators
    && , || , !
    Bitwise Operators
    ~ , & , ^ , | , << , >>
    Assignment Operators
    = , += , -= , /= , *= , %= , >>= , <<= , &= , ^= , |=

    We Can Use scanf() Function For Input Data From User.
    scanf("%d",&variable);
    scanf("%f",&variable);
    scanf("%s",variable);
    scanf("%c",&variable);
    We Can Use printf() Function For Disply Data On Screen.
    printf("%d",variable);
    printf("%f",variable);
    printf("%s",variable);
    printf("%c",variable);

    -- Type Of if --
  • if
  • if..else
  • if...else if
  • Nested if

  • -- Syntax --
    				
    if(condotion)		
    {
    	statement
    }
    else
    {
    	statement
    }
    

    -- Syntax --
    switch(expression)
    {
    	case value:statement..
    	case value:statement..
    	default:statement..
    }
    

    -- While Loop Syntax --
    while(expression)
    {
    	statement..
    }
    
    -- Do..While Loop Syntax --
    do
    {
    	statement..
    }
    while(expression);
    
    -- For Loop Syntax --
    for(expr1 ; expr2 ; expr3)
    {
    	statement..
    }
    

    -- goto Statement --
    lable:
    
    goto lable;
    
    goto lable;
    
    lable:
    

    -- break Statement --
    for(expr1 ; expr2 ; expr3)
    {
    	break;
    }
    
    -- continue Statement --
    for(expr1 ; expr2 ; expr3)
    {
    	continue;
    }
    

    -- Function Declaration Syntax --
    
    <return_type><function_name>(argument.. );
    
    -- Function Definition Syntax --
    
    <return_type><function_name>(argument..)
    {
    	statement..
    }
    
    -- Function Call Syntax --
    
    <function_name>(pass_argument);
    

    -- 4 Type Of Storage Class --
  • auto (by default)
  • register
  • static
  • extern

  • -- Type Of Arrays --
  • One Dimensional Array
  • Two Dimensional Array
  • Multi Dimensional Array

  • -- Creation Of Arrays --
  • 1-D Array int array[5];
  • 2-D Array int array[5][3];
  • Multi Array int array[5][3][2];

  • -- Creation Of Pointer Arrays --
    1-D Array
    int *p = new int[5];
    2-D Array
    int **p = new int*[row_size];
    p[i] = new int[col];

    Pointer is a variable that stores the address of another variable.
    Pointer can make some things much easier , help improve your program's efficiency.
    C pointer is used to allocate memory dynamically(run time).
    -- Pointer Symblo --
    *

    -- Pointer Creation --
    <datatype> *pointer_variable_name; int *p,a=10;
    p = &a;

    -- Pointer Of Pointer Creation --
    <datatype> *pointer_variable_name; int *p = 10,**q;
    q = &p;


    -- About String --
  • String is collection of characters
  • String always terminated by null(\0) character
  • -- String Creation--
  • char name[6] = {'H','E','L','L','O','\0'};
  • char name[] = "HELLO";

  • -- There Are Many Function For String --
  • strcat() : For concatenates string2 at the end of string1
  • strcpy() : copies string2 into string1
  • strlen() : gives the length of string
  • strcmp() : Compare two string , Return 0 if string1 is same as string2
  • strupr() : Convert string to uppercase
  • strlwr() : convert string to lowercase
  • strrev() : get reverse string

  • Structure is variable that gives facility of storing data of differnet data type in one variable

    -- Structure Creation --
    
    struct student{
    		
    	int roll_no;
    	char class;
    	char name[25];
    	float age;
    	char address[20];
    };
    
    -- Structure Variable Creation --

    struct student s1;

    -- Accessing Structure Data --

    You Can Access Data Of Structure By Dot(.) Operator
    s1.name = "india";
    s1.roll_no = 12;

    Union is also same as structure but different is structure variable size is sum of all variable size which are declared in structure while union size is which variable size is big that is size of union.

    -- Union Creation --
    
    union employee{
    		
    	int id;
    	int salary;
    	char employee_name[25];
    	float age;
    	char address[20];
    };
    
    -- Union Variable Creation --

    union employee e1;

    -- Accessing Union Data --

    You Can Access Data Of Union By Dot(.) Operator
    e1.name = "XYZ";
    e1.id = 11;

    -- File operation --

  • Create a new file
  • open an existing file
  • Read from file
  • Write To a file
  • Moving a Specific Location in a file(seeking)
  • Closing File

  • -- File Mode --

  • "r" read
  • "w" write
  • "a" write,overwrite file if it exists
  • "r+" read & write , do not destroy file if it exists
  • "w+" read & write , but overwrite file if it exists
  • "a+" read & write , but append instead of overwrite

  • -- File Function --

  • fopen() : create a new file
  • fclose() : close file
  • getc() : read character from file
  • putc() : write character to a file
  • getw() : read integer from file
  • putw() : write integer to a file
  • fprintf() : write set of data values
  • fscanf() : read set of data values

  • Thank You







    © Design by Baadshah Of Programming

    Developed By Darshit Asalaliya

    www.000webhost.com