{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
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, they’re right associative and can be used in arbitrary expressions.
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern