Docstoc

Review Expression

Document Sample
Review Expression Powered By Docstoc
					Guess The Output - Modulus
Operator
#include <stdio.h>
Void main()
{
  printf(“%d”, 5/2);
  printf(“%d”, 5%2);
  printf(“%d”, 4/2);
  printf(“%d”, 3%2);
}

         http://c.Firdaus-Harun.com - Your Really True Reference in C Programming
Modular or Modulo
 This operator divides the first operand by
  the second and returns the remainder
  rather that the quotient
 E.g:
    ◦ 5 % 2 evaluates to 1
    ◦ 5 % 3 evaluates to 2
   Both operand must be integer types and
    the operator return the remainder as
    an integer type.
               http://c.Firdaus-Harun.com - Your Really True Reference in C Programming
Assignment Operation
 Simple assignment
 E.g: num1 = 7
 num1 is a variable
 = is an assignment operator
 7 is an expression




           http://c.Firdaus-Harun.com - Your Really True Reference in C Programming
Assignment Expression (.cont…)
X = 10
Y=5
X=Y+2
   Value of Expression ? 7
   Result of Expression ? X = 7




              http://c.Firdaus-Harun.com - Your Really True Reference in C Programming
Compound Assignment
 A shorthand notation for a simple
  assignment.
 Five compound assignment :
    ◦ *=
    ◦ /=
    ◦ %=
    ◦ -=
x    *= y equivalent x = x*y
x    *= y + 3 is evaluated as x =
    x*(y+3)
             http://c.Firdaus-Harun.com - Your Really True Reference in C Programming
Postfix Expression
 a++ OR a--
 a = a + 1 OR a = a - 1




            http://c.Firdaus-Harun.com - Your Really True Reference in C Programming
Unary Operator
++a OR --a
a=a+1




          http://c.Firdaus-Harun.com - Your Really True Reference in C Programming
     Precedence & Associativity
!        Unary –       higher precedence

* / %


+    –
<    <= >= >               Associativity: execute left-to-right (except
==        !=               for = and unary – )

&&
||
=
                       lower precedence




                   http://c.Firdaus-Harun.com - Your Really True Reference in C Programming

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:0
posted:7/26/2013
language:Latin
pages:8