Search This Blog


Wednesday, September 18, 2019

#2 Opertaor in C


➤Assignment operator  :-

This operator is used to assign the value in variable .

Example:-

A=10
B=10.5
Name=”COc”

➤Multiple assignment operator :-

This operator is used to assign same value in multiple variables.

Example:-

a = b = c = 10;

➤Compund assignment  :-

  • Assignment  operator is used with arithmetic operator  and bitswise operator. This concept is called compound assignment operator.
  • It is also known as shortcut assignment operator.

Example:-

a = a+10   can be written as  a+=10
a = a *30 can be written as  a*=30

➤Increment operartor (++)  :-

This operator is used to increase the value of variable by 1.

⏩Prefix increment :-

  • Increment operator is used before operand. Eg:- ++a
  • Value of variable is incremented first,then new value is used in operation .

⏩Postfix increment :-

  • Increment operator is used after operand. Eg:- a++
  • Value of variable is used in the operation first, then incremented

Evaluation of prefix and and postfix :

Prefix
Postfix
1.       a=10, b=20
++a    a=11
++b    b=21
a=11
b=21

2.       a=10, b=20
p=++a    a=11
q=++b    b=21
a=11
b=21
p=11
q=21

3.       a=10, b=20
++a    a=11
++b    b=21
p=++a   a=12
q=++b   b=22
a=12
b=22
p=12
q=22



1.       a=10, b=20
a++   a=10
b++   b=20
a=11
b=21

2.       a=10, b=20
p=a++   a=10
q=b++   b=20
a=11
b=21
p=10
q=20

3.       a=10, b=20
a++    a=10
b++    b=20
p=a++    a=11
q=b++    b=21
a=12
b=22
p=11
q=21

➤Decrement operator :-

This operator is used to decrease the value of variable by 1.

⏩Prefix decrement :-

  • Decrement operator is used before operand. Eg:-  --a
  • Value of variable is decremented first,then new value is used in operation .

⏩Postfix decrement :-

  • Decrement operator is used after operand. Eg:-   a--
  • Value of variable is used in the operation first, then decremented.

➤Comma operator :-

  • This operator is used to separate multiple values within parenthesis sign “( )”.
  • In this case last value will be evaluated and assigned in variable.

Case1:-

             a=(10,20,30,40);

      a=40

Case2:- 

               a=10,20,30,40;
       a=10

➤Sizeof operator :-

This operator return the size of data type and variable in byte.

Syntax:-

              sizeof(data type variable)

example:-

·         sizeof(int)    2byte  
·         sizeof(float)   4byte
·         int a; sizeof(a);  2byte
·         sizeof(‘A’)   1byte
·         sizeof(“coc”)   4byte


No comments:

Post a Comment