Ch4 - CSEB114:Principleof programming Chapter 4 Basic C...

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

View Full Document Right Arrow Icon
Click to edit Master subtitle style 7/23/2008 prepared by NI, edited by MAF CSEB 114: Principle of  programming Chapter 4: Basic C Operators
Image of page 1

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

View Full Document Right Arrow Icon
7/23/2008 prepared by NI, edited by MAF Objectives In this chapter, you will learn about: Arithmetic operators Unary operators Binary operators Assignment operators Equalities and relational operators Logical operators Conditional operator
Image of page 2
7/23/2008 prepared by NI, edited by MAF Arithmetic Operators I In C, we have the following operators (note that all these example are using 9 as the value of its first operand) Operation Operator Operand Value After Addition + 2 11 Subtraction - 2 7 Multiplication * 2 18 Division / 3 3 Increment ++ + 10 Decrement -- - 8 Modulus % 2 1
Image of page 3

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

View Full Document Right Arrow Icon
7/23/2008 prepared by NI, edited by MAF Arithmetic Operators II  There are 2 types of arithmetic operators in C: unary operators operators that require only one operand. binary operators. operators that require two operands.
Image of page 4
7/23/2008 prepared by NI, edited by MAF Unary Operator The first assigns positive 3 to a The second assigns the negative value of a to b. i++ is equivalent to i = i + 1 i-- is equivalent to i = i-1 C Operation Operator Example Positive + a=+3 Negative - b=-a Increment ++ i++ Decrement -- i--
Image of page 5

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

View Full Document Right Arrow Icon
7/23/2008 prepared by NI, edited by MAF PRE- / POST-Increment It is also possible to use ++i and --i instead of i++ and i-- However, the two forms have a slightly yet important difference. Consider this example: int a = 9; printf(“%d\n”, a++); printf(“%d”, a); The output would be: 9 10
Image of page 6
7/23/2008 prepared by NI, edited by MAF PRE- / POST-Increment cont… But if we have: int a = 9;
Image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
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