lecture_04 - ECE 190 Lecture 04 Operators and control...

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

View Full Document Right Arrow Icon
ECE 190 Lecture 04 January 27, 2011 1 V. Kindratenko Operators and control structures in C Lecture Topics Operators Conditional constructs Example Lecture materials Textbook § 12.3., 12.4, 13.1, 13.2 Homework None Machine problem MP1.1 due February 2 at 5pm submitted electronically
Background image of page 1

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

View Full DocumentRight Arrow Icon
ECE 190 Lecture 04 January 27, 2011 2 V. Kindratenko Operators Operators are the language’s mechanisms for manipulating values o Example: z = x * y; Expression x * y is evaluated and the resulting value is assigned to variable z three things to know about operators: o function – what it does o precedence – in which order are operators combined o associativity – in which order operators of the same precedence are executed Assignment operator = is the assignment operator o The value on the right of the assignment operator will be assigned to the variable whose name is provided on the left side of the operator The value actually will be copied to the memory associated with the variable name on the left of the assignment operator o Example: a = b + c; If the type of the value on the right of the assignment operator is not the same as the type of the variable on the left of the assignment operator, data type conversion will take place Example: o int x, a; double y, z; z = x + y; <- value of x will be converted to double type before the expression is evaluated a = x + y; <- once evaluated, the sum will be converted to int type before assigning it to variable a Arithmetic operators Defined for int , float , and char data types *, +, -, /, % (modulus) Precedence: *, /, % are executed first, followed by + and – o 2+3x4 = 2+(3x4) Associativity: operators with the same precedence are executed sequentially o 2+3-4+5=((2+3)-4)+5 Parenthesis can be used to override the evaluation order While floating-point addition and multiplication are both commutative (a + b = b + a and
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/24/2011 for the course ECE 190 taught by Professor Hutchinson during the Spring '08 term at University of Illinois, Urbana Champaign.

Page1 / 8

lecture_04 - ECE 190 Lecture 04 Operators and control...

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

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