RAVINDRA'S BLOG

Thursday, 3 May 2018

C

What is C:

  • C is structure oriented programming language.
  • It creates the system applications, that directly interacts with hardware devices, such as drivers,kernels etc.
  • C is the base of the other languages, so it is called as mother of Languages.

Facts about C:

  • C was invented to create operating system called Unix.
  • Most of the software have been implemented using C.
  • Linux OS and RDMS MySQL are written in C.
  • C is a successor of B Language which was introduced around the early 1970s.

Features of C :

  • Reliability
  • Portability
  • Flexibility
  • Interactivity
  • Modularity
  • Efficiency and Effectiveness

Installation of Turbo C++:

  • To write C programming in friendly way we use Turbo C++.
  • Turbo C++ is a Integrated Development Environment and Compiler.
  • Open turbo C++ site and click on the download.
  • Click on turbo C ++ to install.
  • Accept the license agreement and click next.
  • Click on install, to install all the setup programs.
  • Installs all the features.
  • After installation, click finish to launch the application.

what is stdio.h?

  • Stdio.h is library that stores the many standard functions.
  • These functions are use for input and output operations.
  • Examples : printf() and scanf().

Variables:

  • A variable is used to store data, which used in the program in any location
  • Variables can contain letters, digits, characters and underscores.
  • Type of the variables are:
    • Char        : Used to store characters in it.
    • int            : Used to hold or store integer.
    • float         : Used to store the decimal value.
    • double     : Used to hold long data value.
    • void
  • Below are Formats used for print and input the value from or to output console for desired variable.
Format StringMeaning
%dScan or print an integer as signed decimal number.
%fScan or print a floating point number.
%cTo scan or print a character.
%sTo scan or print a character string. The scanning ends at white space.

Rules to name a variable:

  • Variable name must not start with a integer.
  • Blank or Spaces are not allowed in variable.
  • Keywords are not allowed as variable name.
  • C is case sensitive upper and lower case letters are treated as different.

Strings :

  • Strings are one dimensional array.
  • String is group of characters combined as one word.
  • String can be declared in four different ways, for example if I want store "Ravindra"
    • char stringname[] = "Ravindra";
    • char stringname[] = {'R','a','v','i','n','d','r','a','\0'}
    • char stringname[25] = "Ravindra";
    • char stringname[9] = {'R','a','v','i','n','d','r','a','\0'}

Combining two strings :

  • To combine two strings we use concatenate. Syntax: strcat(string1, string2).
Loops :
  • To execute a statement or group of statement multiple times we use loop.
  • Loop are executed using condition.
  • Type of loops:
    • for
    • while
    • do-while
  • for :
    • Syntax of for loop :
                                               for(init, condition, increment)
    •                                          {
                                                /*code declaration*/
                                                }
    • init : Executed first, used to declare loop control variable.
    • Only for the first time, for loop enters into init.
    • condition : Check the condition to enter into the loop or to skip the loop.
    • increment: After the execution of code, it enters into increment and increments the variable.
  • while:
    • Syntax of while loop :
                                               while(condition)
                                               {
                                                /*code declaration*/
                                                }
    • Checks the condition and enters into the loop.
  • do - while :
    • Syntax of do-while loop :
                                                do
                                               {
                                                /*code declaration*/
                                                }while(condition)
    • do - while is name as while, but condition is checked after executing the code atleast once.
  • nested loop:
    • nested loop is nothing but declaring loop inside the loop.
    • example :
                                             for(init, condition, increment)
                                             {
                                                for(init, condition, increment)
                                                {
                                                     /*code declaration*/
                                                }
                                             }

Decision Making :

  • Sometimes we want a statement or group of statements need to be executed in specific period or condition.
  • For this purpose we use decision making.
  • Decision Making are mainly two types:
    •  if statement
      • if
      • if  - else
      • nested if
    • switch statement
      • switch
      • nested switch
  • if  syntax :
    • if uses boolean expressions, boolean expression is true it enters into the code.
    • if ( boolean expression){
      /*code declaration*/
      }
  • if else syntax:
    • if - else is nothing but if condition is not true it executes code in else.
    • if(boolean expresssion){
      /*code declaration*/
      }
  • nested if  syntax:
    • declaring if inside if.
    • if(boolean expression){
         /*code declaration*/
        if(boolean expression){
          /*code declaration*/
       }
      }
  • switch syntax : 
    • switch expression variable value is compared with each case constant expression, which ever case expression matches with expression value enters the conditions
    • switch(expression){
      case constant-expression :
      /*code declaration*/
      case constant-expression :
      /*code declaration*/
      }
  • nested switch syntax :
    • switch(expression){
      case constant-expression:
      /code declaration*/
         switch(expression){
           /*code declaration*/
         }
      }