t04BVariablesAndExpressionsAssignment

t04BVariablesAndExpressionsAssignment - Variable...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Dale Roberts Variable Declarations, Data types, Expressions - Assignments www.kite-legends.blogspot.com
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Dale Roberts Assignment Operators Assignment Operators Syntax: Syntax: var = expression; Assign the value of expression to variable ( var ) Example : int x, y, z; x = 5; y = 7; z = x + y; int x, y, z; x = y = z = 0; int x = y = z = 0; int i, j; float f, g; i = f = 2.5; g = j = 3.5; i = 2; f = 2.5; g = 3.0; j = 3; Z = (x = 5) + (y = 7) much faster same as x = (y = (z = 0)); wrong ! int x = 0, y = 0, z = 0; www.kite-legends.blogspot.com
Background image of page 2
Dale Roberts Short Hand Assignment Short Hand Assignment Syntax Syntax f = f op g f = f op g can be rewritten to be f op= f op= g g such as: a = a + 2 a += 2, a = a - 2 a -= 2, a = a * 2 a *= 2, a = a / 2 a /= 2, a = a % 2 a %= 2, a = a << 2 a <<= 2, a = a & 2 a &= 2, a = a | 2 a |= 2, a = a ^ 2 a ^= 2 No blanks between op and = x *= y + 1 is actually x = x * (y+1) rather than x = x * y + 1 Example
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/08/2010 for the course CSE 2017 taught by Professor Kittu during the Spring '10 term at APIIT.

Page1 / 7

t04BVariablesAndExpressionsAssignment - Variable...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online