Posted By:
11 Jun, 2013 12:15 am PDT

Assignments and operators in C and C++

How do we use assignments and operators in c language?

An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.

C language is rich in built-in operators and provides following type of operators:

  1. Arithmetic Operators
  2. Relational Operators
  3. Logical Operators
  4. Bitwise Operators
  5. Assignment Operators

Please watch the video for details....

Was it useful?  

Well , we all learned the basic math in lower grades. There is nothing new to the arithmetic operators in C . All is the same.

+    addition or unary plus
-     subtraction or unary minus
*    multiplication
/     division
%    remainder after division (modulo division)


We have another set of operators called Increment and Decrement operators , this will be helpful in "loops " . We will get to the loops later.

Let a=5 and b=10

a++;        //a becomes 6-post increment
a--;          //a becomes 5-post decrement
++a;        //a becomes 6-pre increment
--a;          //a becomes 5-pre decrement.

POST - this means first the value 5 is assigned to a variable and the operation wrt to the sign is done.


PRE - this means that the value is first incremented/decremented depending on the sign and then assigned to the variable.

To write conditions ,we need relational and logical operators.

Relational operators.
==       Equal to                        5==3 returns false (0)
>         Greater than                  5>3 returns true (1)
<         Less than                       5<3 returns false (0)
!=        Not equal to                   5!=3 returns true(1)
>=      Greater than or equal to  5>=3 returns true (1)
<=      Less than or equal to       5<=3 return false (0)


Logical Operators

&&                 Logial AND       If c=5 and d=2 then,((c==5) && (d>5)) returns false.
||                  Logical OR        If c=5 and d=2 then, ((c==5) || (d>5)) returns true.
!                    Logical NOT      If c=5 then, !(c==5) returns false.

We also have another category of operator called Ternary operator ( Conditional Operator )

The syntax is: 



If the Conditional_expression is true then Expression1 is executed.
If the conditional_expression is false then Expression2 is executed.

Please have a look at the file attached to understand how operators work.

Was it useful?  

Please login to reply to this problem.

Related Problems on Fixoncloud