Instructions and operators in C - C tutorials

                           Instructions and operators 


C tutorials
operators




A  c program is set of instructions just like a recipe - which contains instructions to prepare a particular dish .

Types of instructions :-

1. type declaration instructions.
2. control instructions.
3. Arithmetic instructions.

Type declaration instruction : -

int a;
float b;#programmers

other variations:-
int i = 10; 
int j = i;
int a = 2;

int j1 = a+ j - i;

float b = a+3;   float a = 1.1;  -  💣-- ERROR ! as we are trying to use                                                                                    before assigning it.


int  a,b,c,d;
a=b=c=d =30;                             value of a,b,c,d each assign will be 30.

Arithmetic instructions :-

int i = (3 * 2) +1👈 operands
                ☝
          operator
operands can be int (integer) , float (real value) etc.
+ , -,/,* are arithmetic operators.

int b= 2  , c=3;
int z; z=b*c;  💨 legal..
int z;    b*c=z; 💨 not allowed..

% =  Modular division operator
% = returns the ramainder
% = cannot be applied on float
% = sign is same as of numerator (-5%2=-1)

Note :-
no operator is assumed to be present.

int i= a b; 👈  invalid.
int i = a*b; 👈   valid.

There is no operator to perform expontention in C however, we can use pow(x,y)   from(<math.h>)

Type Conversion :-

An arithmatic operation between

int and int = int 

int and float = float

float and float = float

5/2  = 2            5.0/2 = 2.5

2/5 = 0             2.0/5 = 0.4

Note :-

int a =3.5;            in this case 3.5(float) demoted to int beacuse a is not able to                                             store float.

float a = 8;          float a will store 8.0
                                8- 8..0 promotion to float...


Operator precedence in C :-

3 * x - 8y  is  (3x) - (8y)  or  3(x-8y) ?

in C language simple mathematical rules like BODMAS, no longer applies.

The answer to above question provided by operator precedence and associativity.

Operator precedence in C :-

The following table shows operator priority...

1st  :-  *,/,%

2nd :- +,-

3rd :- =

operator of higher priority evaluates firstly in absense of paranthesis.

Operator Associativity in C :-

When operator of equal priority then tie is taken care by associativity.

ex.
x * y/z      =    (x*y)/z
x / y*z      =   (x/y)*z

*,/ follows left to right associativity..

Control Instructions :-

Determines the flow of program ...


Four types of control instructions :-
  • sequence control instructions
  • loop control instructions
  • Decision control instructions
  • case control instructions. 

Operator :-

This is symbol used to perform some operations on variables, operands or with the constants.
In some cases operator can manage with single operations and in other cases operator requires 2 operand to perform operations.

There are 9 types of operators are :-

1. Arithmetic operator
2. Increment operator                                               
3.Decrement operator
4.Assignment operator
5.Logical operator
6.Conditional operator
7.Comma operator
8.Size of operator
9.Bitwise and others operator.

1.Arithmetic operator :-


These operator is for numeric calculations and measures only.

these are several unary and binary arithmetic operator.

Unary arithmetic operator required in this section.

One operand handed such as +,-,++,--,! etc.

These operators are addition, subtraction, multiplication, Division.
But binary arithmetic operator required two operands and operators are addition +,subtraction -,multiplication *,division /,modules %.

2.Icreament and decrement operator :-

The unary operator ++,-- is used as increment and decrement processed on single operand.
Increment boost the value of variable by one.
Decrement return or decrease value of variable by one.
These operator can only used with variables.

For prefix --
Ex.
let x=36;
y=++x;
y=x;
x=x+1;

For postfix --
Ex.
let m=90;
n=m++;
n=m;
m=m+1;

3.Assignment operator :-

The value can stored in variable with help of assignment operator.
The symbol of assignment operator is ( = ).

if we have lot of variables contained various values then we can store to one variable due to help of assignment operator.
assignning all variables value to another one variables hence our value will
 assign to another one variable.

Ex.
let,  int x=y;
int sum=x+y+z;

assigning of values are more easier and simplest way to less load on program or to create small program.

4.Logical operator :-


C language has three logical operator :

operator                      meaning

   &&                                  AND
   ||                                      OR     
    !                                      NOT

In logical AND if both condition are true then result will true otherwise false.
In logical OR if both condition are false then result will false otherwise true.
Logical NOT is unary operator.

5. Conditional operator :-


it is also called as ternary operator.
it requires three expression as operand and it is represented as ?, : .

syntax :
exp1 ? exp2 : exp3.
exp1 will evaluated first . it is true then exp2 will return value . if false then exp3.


6.comma operator :-

comma operator is used to divide or specify expression in each seprate manor.
All expression sepereted by comma and evaluated from left to right.

ex:
int a,b,,d;

7.Bitwise operator :-

Bitwise operator gives permission to programmer to access data at bit level.

All bitwise operator are : 

1.one's complement (~) : 0 changes to 1 and 1 changes to 0.
2.bitwise and (&) : 
3.bitwise or(|): it is used to set bit in number.
4.bitwise XOR(^):
5.left shift (<<):
6.right shift(>>):

These operator can operate on integer and character value not on float and double.






No comments

This website is only for educational purpose, it is not related to any organization. This website helps to beginners in programming to learn fast.

Powered by Blogger.