{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# 4 - ICS103 Programming in C Lecture 4 Data Types Operators...

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

1 ICS103 Programming in C Lecture 4: Data Types, Operators & Expressions

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

View Full Document
2 Outline C Arithmetic Expressions Operators Data Type of Expression Mixed-Type Assignment Statement Type Conversion through Cast Expressions with Multiple Operators Writing Mathematical Formulas in C Programming Style
3 Why Arithmetic Expressions To solve most programming problems, you will need to write arithmetic expressions that manipulate type int and double data. The next slide shows all arithmetic operators. Each operator manipulates two operands , which may be constants, variables, or other arithmetic expressions. Example 5 + 2 sum + (incr* 2) (B/C) + (A + 0.5)

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

View Full Document
4 C Operators Arithmetic Operator Meaning Examples + ( int , double ) Addition 5 + 2 is 7 5.0 + 2.0 is 7.0 - ( int , double ) Subtraction 5 - 2 is 3 5.0 - 2.0 is 3.0 * ( int , double ) Multiplication 5 * 2 is 10 5.0 * 2.0 is 10.0 / ( int , double ) Division 5 / 2 is 2 5.0 / 2.0 is 2.5 % ( int ) Remainder 5 % 2 is 1
5 Operator / & % Division : When applied to two positive integers, the division operator (/) computes the integral part of the result by dividing its first operand by its second. For example 7.0 / 2.0 is 3.5 but the but 7 / 2 is only 3 The reason for this is that C makes the answer be of the same type as the operands. Remainder : The remainder operator (%) returns the integer remainder of the result of dividing its first operand by its second. Examples: 7 % 2 = 1, 6 % 3 = 0 The value of m%n must always be less than the divisor n. / is undefined when the divisor (second operator) is 0.

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

View Full Document
6 Data Type of an Expression The data type of each variable must be specified in its declaration, but how does C determine the data type of an expression?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}