C Programming language

adplus-dvertising
C Programming Language: C Instruction
Previous Home Next
C instruction are of basically three types :

1. Type Declaration instructions in C Language

This instruction is used to declare the type of variables being used in the program. Any variable used in the program must be declared before using it in any statement. The type declaration statements is written at the beginning of the main() function. The main purpose of type declaration instruction is to declare the type of variable C program.

int num;
char c;     // Type Declaration
float f;
main()
{
   // Statement
}

There are several suitable variations of the type declaration instruction:

  • While declaring the type of the variable we can also initialize it.
                	// Example
                    int num=10, j=23;
                    float a=1.05, b=1-55+24;
  • The order in which we define the variable is sometimes important sometimes not.
    int i=10, j=25; /**is same as**/ int j=25, i=10;
    /** However **/
    float a=1.5, b=a+3.1;	/** is alright  **/ 
    /** but **/
    float b=a+3.1, a=1.5;	/** is not alright  **/
    
  • The following statements would work
    int a, b, c, d;
    a=b=c=d=10;
    /** However the following statement would not work **/
    int a=b=c=d=10;
    /** because here once again we are trying to use b without defining it **/
2. The Arithmetic Instruction in C

A C arithmetic instruction consists of a variable name on the left hand side of = and variable names & constants on the right hand side of = The variable and constants appearing on the right hand side of = are connected by arithmetic operators like +, -, * and /.

Three types of C Arithmetic Statement

  1. Integer mode arithmetic statement : This is an arithmetic statement which all operands are either integer or integer constants.
     int i, j, l, m;
     i=i+1;
     m=i* j +l;
    
  2. Real Mode Arithmetic Statement : These are arithmetic statement in which all operands are either real constant or real variable.
     float si, roi, p, q ;
     si = roi*p*q/100.0;
    
  3. Mixed mode arithmetic statements : this is an arithmetic statement in which some of the operands are integer and some of the operands are real.
     int a, b, c, num ;
     avg = ( a + b+ c + num)/4;
    
3. Control Instructions in C

The ‘Control Instructions’ enable us to specify the order in which instructions in a program are to be executed. or the control instructions determine the ‘flow of control’ in a program.

There are four types of control instructions in C.

  1. Sequence Control Instruction: The Sequence control instruction ensures that the instructions are executed in the same order in which they appear in the program.
  2. Selection or Decision Control Instruction: Decision instructions allow the computer to take a decision as to which instruction is to be executed next.
  3. Repetition or Loop Control Instruction: The Loop control instruction helps computer to execute a group of statements repeatedly.
  4. Case Control Instruction same as decision control instruction.
Previous Home Next