lecture03-jan26 - 1 EE312 - Lecture 3 Announcements Read...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: 1 EE312 - Lecture 3 Announcements Read chapters 3 and 4 in the book Assignment 1 due on Friday Topics for today will address: More on the assignment statement Numerical expressions Number storage formats (in Ch. 7) Will use formatted IO functions in examples: printf( . . . ), scanf( . . . ) These are in Ch. 3 (read it) and will be covered next time TA Lab Hour Schedule Time (24 hr.) Mon Tue Wed Thu Fri 9:00:00 Arun Yen-Yu Arun Yen-Yu Yen-Yu 10:00:00 Arun Yen-Yu Arun Yen-Yu 11:00:00 Karthick Karthick Arun Yen-Yu Yen-Yu 12:00:00 Karthick Karthick 13:00:00 mahesh Karthick/mahesh mahesh 14:00:00 mahesh Arun/mahesh 15:00:00 Madhumitha Arun/mahesh Madhumitha 16:00:00 Madhumitha Madhumitha mahesh 17:00:00 Madhumitha 18:00:00 Madhumitha Chaithanya 19:00:00 Karthick Chaithanya Madhumitha 20:00:00 Chaithanya Karthick Chaithanya 21:00:00 Chaithanya Chaithanya 22:00:00 Chaithanya 23:00:00 Assignment For example, the statements float total; int quarters; total = 0.0; quarters = 12; total = total + quarters * 0.25; means take the value in quarters, multiply it by 0.25, add that result to the value currently in total and then, finally place the result back into the variable named total. Any value that was in total before the assignment is made is overwritten by the new value. total 0.0 quarters 12 3.00 /* What does this code do? */ float total = 0.0; int quarters, dimes, nickels, pennies; /*assume that the above have values now*/ total = quarters * .25 + dimes * .10 + nickels * .05 + pennies * .01; Assignment (cont.) Assignment is a true operator, just like + and *. The value of v = e; is the value of v after the assignment. Assignments can be chained together: i = j = k = 0; The = operator is right associative, so this statement is equivalent to i = (j = (k = 0)); The assignment operator may appear inside of any expression: i = 1; k = 1 + (j = i); printf("%d %d %d\n", i, j, k); /* prints "1 1 2" */ Hiding an assignment inside a larger expression is not a good idea and is discouraged. Compound Assignment In addition to the simple assignment operator =, C provides ten compound assignment operators, including these five: += -= *= /= %= The expression v += e; is equivalent to v = v + e; except that v is evaluated only once in the former expression. The other compound operators have similar meanings. The compound assignment operators have the same properties as the = operator; in particular, theyre right associative and can be used in arbitrary expressions....
View Full Document

This note was uploaded on 01/24/2010 for the course EE 312 taught by Professor Shafer during the Spring '08 term at University of Texas at Austin.

Page1 / 4

lecture03-jan26 - 1 EE312 - Lecture 3 Announcements Read...

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

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