C instruction
- A programming is nothing but a set of instruction. The program behaves as per the instruction.that we give in it .Different instruction help as achieve different tasks in a program.
- In the last chapter we show how to write c program in this program knowingly and unknowingly we use used instruction to achieve the intended of the program. .
INSTRUCTION IN C LANGUAGES |
There a basically three types of instruction in c :
1) Type declaration instruction - This instruction is used to declare the type of variables used in a C program.
2) Arithmetic instruction- This instruction is used to to perform arithmetic operations on constant and variables.
3) Control instruction - This instruction is used to control the sequence of various statements in a C program.
Since , the elementary C programs would usually contain om;y the type declaration and the arithmetic instruction.
1) Type Declaration Instruction
- This instruction is used to declare the type of variable being used in the program. any variable used in the program must be declare before using it in any statement. tye type declaration statement is written at the beginning of main () function .
EX:
int bas ;
float rs ;
char name, code ;
- There are several subtitle variations of the type declaration instruction.these are discussed below :
1) While declaring the type of variable we can also initialize it as shown below .
EX:
int=10,j=25;
float a=1.5, b=1.99+2.4*1.44;
2) The order in which we define the variables is sometimes important sometimes not.
EX :
INT I=10 , J=25;
is same as
int j = 27, i=10;
However ,
float a =3.6, b=a+5.8;
is alright ,but
float b=a+5.8,a=3.6;
is not . this is because here we are trying to use a even before defining it.
3) The following statement would work
ex :
int a,b,c,d;
a=b=c=d=10;
However ,the following statement would not work
int a=b=c=d=56;
once again we are trying to use b(to assign a) before defining it.
2) Arithmetic Instruction
- A C arithmetic instruction consists of a variable name on the left hand side of = and variable names & constant on the right hand side of = The variables and constants appearing on the right side of= are connected by arithmetic operator like + , -, * , /
EX :
int ad;
float kot, deta,alpha, beta,gamma;
ad= 3200
kot=0.0065;
deta alpha*bet/gamma+3.2*2/5;
HERE
* ,- ,+ ,/ .are the arithmetic operators.
=is the assignment operator.
2,5 and 3200 are integer constants.
3.2 and 0.0065 are real constants.
ad ad is an integer variable.
kot, deta, alpha, beta,gamma, are real variable
- The variable and constants together are called 'operator' . while executing an arithmetic statement the operands on right hand side are operated upon by the 'arithmetic' 'operator' and the result is then assigned,using the assignment operator, to the variable on left-hand side.
a) Integer mode arithmetic statement- This is an arithmetic statement in which all operands are either integer variable or integer constants.
B) Real mode arithmetic statement -this is an arithmetic statement in which all operands are either real constants or real variables.
C) Mixed mode arithmetic statement -This is an arithmetic statement in which some of the operands and integer and some of the operands are real.
Though Arithmetic instruction look simple to use
SOME NOTE PLEASE FOLLOWING POINTS CAREFULLY
A) C allows only one variable on left side of =. That s, z=k*1 is legal ,whereas k*1=z is illegal
B) In addition to the division operator C also provides a modular division operator. This operator. This operator returns the reminder on dividing one integer with another.Thus the expression 10/2 yields 5, whereas ,10% 2 yields 0. Note that the modulus operator (%) can't be applied on a float. Also note that on using % the sign of the reminder is always same as the sign of the numerator. Thus -5% 2 yields -1 , whereas, 5% -2 yields 1.
C) An arithmetic instruction is at times used for storing character constants in character variables.
When we do this the ASCII values of the character are stored in the variables. ASCII values are used to represent any character in memory.
D) Arithmetic operations can be performed on ints ,floats and chars are performed on the ASCII values of the character and not on character themselves. The ASCII values of 'a' and 'b' are 97 and 98 and hence can definitely added.
E) No operator is assumed to be present. It must be written explicitly. in the following example example, the multiplication operator after b must be explicitly written.
F) Unlike other high level languages ,there is no operator for performing exponentiation operation.Thus following statement are invalid.
EX :
a=3*2 ;
b=3^2;
3) CONTROL INSTRUCTION IN C
a) Sequence Control Instruction
b) Selection or Decision Control Instruction
c) Repetition or Loop Control Instruction.
d) Case Control Instruction
THANK YOU !!
C) Mixed mode arithmetic statement -This is an arithmetic statement in which some of the operands and integer and some of the operands are real.
Though Arithmetic instruction look simple to use
SOME NOTE PLEASE FOLLOWING POINTS CAREFULLY
A) C allows only one variable on left side of =. That s, z=k*1 is legal ,whereas k*1=z is illegal
B) In addition to the division operator C also provides a modular division operator. This operator. This operator returns the reminder on dividing one integer with another.Thus the expression 10/2 yields 5, whereas ,10% 2 yields 0. Note that the modulus operator (%) can't be applied on a float. Also note that on using % the sign of the reminder is always same as the sign of the numerator. Thus -5% 2 yields -1 , whereas, 5% -2 yields 1.
C) An arithmetic instruction is at times used for storing character constants in character variables.
When we do this the ASCII values of the character are stored in the variables. ASCII values are used to represent any character in memory.
D) Arithmetic operations can be performed on ints ,floats and chars are performed on the ASCII values of the character and not on character themselves. The ASCII values of 'a' and 'b' are 97 and 98 and hence can definitely added.
E) No operator is assumed to be present. It must be written explicitly. in the following example example, the multiplication operator after b must be explicitly written.
F) Unlike other high level languages ,there is no operator for performing exponentiation operation.Thus following statement are invalid.
EX :
a=3*2 ;
b=3^2;
3) CONTROL INSTRUCTION IN C
- As the name suggests, the 'control instruction' enable us to specify the order in which the various instruction in a program are to be executed by the computer. in other words , the control instruction determine the 'follow of control' in a program. There are four types of control instruction in C.
a) Sequence Control Instruction
b) Selection or Decision Control Instruction
c) Repetition or Loop Control Instruction.
d) Case Control Instruction
- The Sequence Control instruction ensure that the instruction are executed in the same order in which they appear in the program.
- Decision and Case control instruction is to be executed next. The Loop control instruction is to be executed next.
- The loop control instruction helps computer to execute a group of statements repeatedly.