CSADPRG_mod4_assignment_statements

original file
this is unedited

assignment statements

simple assignments

In PL/1: A = B = C;

int main()
{
   int a = 3;
   int b = 2;
   int c = 1;
   a = b = c;
   printf("%d %d %d",a,b,c);
}
// output 1 1 1

multiple assignments

x =2  
y =3  
x,y = y,x  
print(x,y)

conditional targets

($flag ? $count1 : $count2) = 0;

this is equivalent to

if ($flag) {  
   $count1 = 0;  
} else {  
   $count2 = 0;  
}

compound assignment operators

unary assignment operators

sum = ++ count;
// is equivalent to
count = count + 1;  
sum = count;

//POSTFIX
sum = count ++;
//is equivalent to
sum = count;  
count = count + 1;

assignment as expression

c: while ((ch = getchar()) != EOF) { ... }

a = b + (c = d / b) - 1

Assign d / b to c  
Assign b + c to temp  
Assign temp - 1 to a

if (x=y) instead of if (x==y)

assignment in functional programming languages

in haskell, if an identifier x is declared by let x = 3 then the value of x will always be 3. it can't be changed by assignment.

mixed mode assignment