Instructions in C- Language- SeaOfComputer

 Instructions of a C-Program

instructions of c program


In a C-program, we use several variables, constants, keywords and identifiers in different manner to get the desired solution of a programming problem. 

The C-program is also called as the collection of several instructions in sequential manner. These instructions are related with each other to solve a specific problem. The instructions of a C-program are also called Programming Statements. 

Thus, a programming statement can be defined as "a single line instruction to carry out some action". 

These instructions are of following types depending on their action-

Declaration Instructions 

Algebric expressions 

Input-Output Instructions 

Control Instructions 

It is not necessary to use all types of the instructions in a C-program. A C-program can hold any number of C-instructions to describe the operations. 


Instruction in C- Language


Declaration Instructions :

The Declaration instructions are used to specify the data type of variables, which need to be used within the program. 

All the variables must be declared before their use in the program. The declaration needs the data type and variable name. 

So the declaration restrict the data entry in a specified variable by specifying its data type. 

The syntax used for declaration instruction is as follows-

[datatype variablename;]

Each declaration statement must end with a semicolon (;)


Example : 

                          int num1; 

                          int num; 

                          float rate; 

                          char sname;


Sometimes, we need several variables of same data type, then it is not required to declare all such variables as separate declaration statements.

 But we can declare all such variables in single declaration instruction by separating the variable name with comma sign (,).


Example : 

int num1, num2;                    [Variables num1 and 'num2 are integer typa]
float rate, salary, discount;    [Variables rate, salary and discount are float type]
char sname, cname;               [Variables sname, name are of character type]



Algebraic Expressions :

The algebric expressions are oftenly called "Arithmetic Instructions". Generally an algebric expression contains at least one operator with operands. 

The arithmetic instructions use the arithmetic operators with the operands. The assignment operator also constitutes an important part of any arithmetic instruction. 

If we use the constants in an arithmetic instruction, then the constants are always placed to the right side of assignment operator. The arithmetic operators need to be used strictly in an arithmetic instruction. 


Example  : 

(i) x = a+b;        

(ii) c = a*10;        It is invalid because there is no 

(iii) z = 20;           operator used between the operands 

(iv) t = x;                    'a' and '(a + b)'. 

(v) num = a(b+c) 


In the instruction (i) we have used only variables with addition and assignment operators So the data values stored in the variables 'a' and 'b' are added and the result is stored in the variable 'x'. 


In the instruction (ii), the constant and variables both are used. The multiply operation performed on the variable 'a' and constant value 10 and the result is stored to the variable c. 


In the instruction (iii), we have used only assignment operator, which stores the constant data value on right side to the operator in the variable 'z' to the left side of assignment operate. 


The instruction (iv) also describes the assignment of data value from one variable to another variable. But point to remember is that the data value from right side of assignment operator (either constant or variable) is always stored to the operand on left side of the assignment operator (always one variable). 


Sometimes, many individual expressions are collected and enclosed within the pair of braces { }. Then the block of braces is referred to as the compound statement. The individual expression may be arithmetic instructions or control instruction or any other compound statement.


Example  :

                       {

                       X = 10; 

                       y = x"2; 

                       2 = X+y'; 

                       }


An individual arithmetic instruction may contain any type of variables or constants as the operands. Based on the type of operands used, an arithmetic instruction may be of following types- 


(a) Integer arithmetic instructions - 

These arithmetic instructions contain only integer variables or constants. 

Example  : 

                     int x = 10, y = 20, z; 

                     z = x+y: 


(b) Real arithmetic instructions - 

The arithmetic instruction contains only Real variables or constants. 


Example  :      

                      float price, discount;

               price = 15.60; 

              discount = (price"7.5)/100.0; 


(c) Mixed arithmetic instructions - 

The arithmetic instruction contains the operands of different types such as integer and float both. 


Example : 

              float ta, da; 

               int x, y. salary; 

               x=10; 

               y=20; 

               salary=5000; 

               ta=(salary"15.4)/100: 


The expressions can also be logical representing some logical conditions and returns the result either True (1) or False (0). The logical expressions use the comparison operators like ==,<, >, <=, etc.


Example : 

                       x=y         a=10 

                       x<=y       b>=50 

                       x!=y        c!-100 


Input-Output Instructions 

The Input instructions are associated with the taking of input from input devices (keyboard etc) and supplying them to the program for processing. For this purpose, the standard library of C-language provides several function (like scanf() function).

The Output instructions are used to obtain the output result from after processing.The output result is send to the output device (such as monitor screen) by several standard library functions (like printf() function).  


Control Instructions 

The control statements are used to control the flow of various instructions in a C-program, It means, the sequence of statements execution is controlled by the control instructions.The control instructions are of following types - 


(a) Sequence Control Instructions - 

These instructions take care of the execution sequence of instructions. The programming instructions should execute in the order of their appearance in the program. 


(b) Decision Control Instructions - 

These instructions allow the programmer to make the execution of some instructions decision based. 


(c) Repetition Control Instructions - 

These instructions control the execution of a group of statements repeatedly.


Related Posts Here :-

Post a Comment

Previous Post Next Post