Chapter 2
Instructions & Operators

A C program is a set of instructions and rules we have to follow them and write our code by using that instructions
Think about a recipe in my case I choose maggi
How to prepare a maggi
We have some instructions to make maggi
1. Take a pan
2. Put some water 2 cups
3. Break maggi and put in water
4. Put masala into maggi
5. Wait for 2 minutes.
6. Ready to serve
So this is the example of instructions in daily life so in programming the proceess is simmilar. Let’s gets into it.
Types of instructions
- Type declaration instruction
- Arithmetic instruction
- Control instruction
Type declaration instruction
To declare the type of variables used in a C program.
- Any variable used in the program must be declared before using it in any statement
- This instruction is used to declare the type of variables being used in the program.
- The type declaration statement is written at the beginning of main( ) function
Example ⤵️
int a ; int store integer
Float b; float is for decimal number
Char c; char is for character
While declaring the type of variable we can also initialize it as shown below.
int i = 10, j = 25 ;
float a = 1.5, b = 1.99 + 2.4 * 1.44 ;
The order in which we define the variables 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. This is because here we are trying to use a even before defining it.
The following statements would work.
int a, b, c, d ;
a = b = c = 10 ;
However, the following statement would not work.
int a = b = c = d = 10 ;
Once again we are trying to use b (to assign to a) before defining it.

Arithmetic instructions
We all know that the study of numbers, especially the properties of the traditional operations on them—addition, subtraction, multiplication, division, is arithmetics
In c programming we have + ,- ,/ ,* , % , ++, —
Note: in c programming no +++ or --- operator present

Program for all operators
// Working of arithmetic operators
#include
int main()
{
int a = 9,b = 4, c;
c = a+b;
printf(“a+b = %d \n”,c);
c = a-b;
printf(“a-b = %d \n”,c);
c = a*b;
printf(“a*b = %d \n”,c);
c = a/b;
printf(“a/b = %d \n”,c);
c = a%b;
printf(“Remainder when a divided by b = %d \n”,c);
return 0;
}
Type Conversion
Int and int = int
Int and float = float
float and float = float
5 / 2 = 2
2 / 5 = 0
5.0 / 2 = 2.5
2.0 / 5 = 0.4
Or we can’t store value like this
Int a = 3.5; here 3.5 is float so a is not able to store this number
However float a = 8; a will store 8.0 (promotion to float)
Operator precidence in C
In C language simple mathematical rules like BODMAS no longer applies. The answer to the above question is provided by operator precedence and associativity .
Operator precedence
Priority operators
1st. . * / %
2nd. + -
3rd. =
Operators of higher priority are evaluated first in the absence of parentheses ()
Operator associativity
When operators of equal priority are present in an expression the Tie is taken care of by associativity
x * y / z ➡️ (x/y)/z
x/ y * z ➡️ (x/y)*z
*. /. Follows left to right associativity
Control instructions
Control statements enable us to specify the flow of program control; ie, the order in which the instructions in a program must be executed. They make it possible to make decisions, to perform tasks repeatedly or to jump from one section of code to another.
There are four types of control instructions in C programming.
- Sequence control instruction
- Decision control instruction
- Loop control instruction
- Case control instruction
All c progam is available on this link below click here see there