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

Info icon This 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
Image of page 1

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

View Full Document Right 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
Image of page 2
Image of page 3
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