3_Answers_3-1 - CIS 15AG 1 Answers Chapter 3: Structure of...

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

View Full Document Right Arrow Icon
CIS 15AG Answers Chapter 3: Structure of a C Program: Expressions and Statements 1. Evaluate the following arithmetic expressions. For each result circle the appropriate type (int, float, double, char). Answer: Expression Value Type a. 11 / 2 (int divided by int is int) 5 int , float, double, char b. 5 + 2 * 2 = 5 + 4 = 9 9 int , float, double, char c. 11 / 2 * 2 = 5 * 2 = 10 10 int , float, double, char d. 15 / 5.0 Implicit type conversion: first int is promoted to double: 15 is promoted to 15.0 , then 15.0 / 5.0 gives 3.0 , a double (See page 89). 3.0 int, float, double , char e. 11 % 5 (remainder) 1 int , float, double, char f. 5 % 11 (remainder) 5 int , float, double, char g. ( 2 + 2 * 3 + 4 * ( 5 - 1 ) ) / 2.0 = ( 2 + 6 + 4 * 4 ) / 2.0 = ( 2 + 6 + 16 ) / 2.0 = 24 / 2.0 = 12.0 12.0 int, float, double , char What is the type of a literal integer constant? In other words, in the following program fragment, what is the type of 4 ? int a; int b; a = b + 4 ; The answer to this question is int . The type of a literal floating point constant is double , not float as we might be tempted to say. Why is this important? It is important to understand the warnings given by the compiler; for instance: float num = 3.14; 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
CIS 15AG Answers Chapter 3: Structure of a C Program: Expressions and Statements In this example num is of type float but 3.14
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

3_Answers_3-1 - CIS 15AG 1 Answers Chapter 3: Structure of...

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

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