C Instructions With Examples

I hope before continuing to this tutorial you must have written the basic printf() and scanf() programs. If you didn’t then I strongly recommend you to do it. Read previous tutorials from here.

Anyways so far we have covered the very basic programs of C. We have used many instructions in it. So today I will tell you about the C instructions.

What are C Instructions?

There are basically three types of C instructions.

1. Type Declaration Instruction
2. Arithmetic Instruction
3. Control Instruction

We have covered first two types of instructions already in our previous turorials but I will tell you about certain nuances of these instructions now. So lets try to analyse them one by one.

Type Declaration Instruction

As its name suggests it is used to declare type of variables in C language. It is must that you have to declare the type of variable before using it. And it is also must that these type declaration instruction should be provided in the beginning of the program (just after the main()).

Now lets learn about some variations in them.

a) We can initialize the variable at the time of its declaration.

int a=3;
char a=’d’;
int a=7*3*2;

b) Remember the order of variables while declaring them.

int i=3,j=5; is same as int j=5,i=3;

float a=5.5,b=a+7.1; is alright, but
float b=a+7.1,a=5.5; is not valid. 

It is because in the above declaration we are trying to use variable a even before defining it.

c) Another interesting point while declaring variables is

Below instruction will work
int a,b,c,d; 

However, the following statement would not work.
int a=b=c=d=10 ;

Now again we are trying to use variables even before defining them.

I hope now you must have understand the importance of type declaration instruction. So we can only use variables after defining them. And these definition should be written at the starting of main() body. We cannot define variables anywhere else in the program. If you do so, it will result in an error.

Arithmetic Instruction

General form of an arithmetic instruction follow rules given below.

i) It should contain one assignment operator i.e. =.
ii) On the left side of =, there should be one variable.
iii) On the right side of =, there should be variables and constants.
iv) And those variables and constant will be connected by some arithmetic operators like +,-,*,/,%.

int a=12;
float b,c=2.2; 

What are operands?

These variables and constants together are called operands. These operands are connected by arithmetic operators.

How the execution of arithmetic instructions takes place?

Firstly all the variables and constants on the right hand side of assignment operator (=) is calculated. After that the result will be stored in the variable on the left hand side of assignment operator.

Now let’s checkout certain nuances of arithmetic operators

1. It is compulsory to use only one variable on the left hand side of =.

c=a*b is correct,
whereas a*b=c is incorrect.

2. A operator named modular operator (%) is also used in C. This modular operator will return the remainder to left hand side variable of assignment operator. It cannot be used with floats. It will return the same sign as the numerator has.

5 %-2=1

Control Instruction

This instruction is used to shift the control of program as per the user or programmer wants. This instruction contains decision making, looping and more. This is a bit advance topic. We will cover this topic in our later tutorials.

1 thought on “C Instructions With Examples”

Leave a Comment

Your email address will not be published. Required fields are marked *