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

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

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

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

View Full Document
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
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

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

View Full Document
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.
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--

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

View Full Document
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
7/23/2008 prepared by NI, edited by MAF PRE- / POST-Increment cont… But if we have: int a = 9;

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern