Values are represented by constant expressions possibly involving previous

Values are represented by constant expressions

This preview shows page 5 - 7 out of 9 pages.

Values are represented by constant expressions , possibly involving previous enumeration constants. The enumeration constants are separated by commas, and a comma can follow the last constant. For instance, enum rating {strongly_disagree = 1, disagree, mod_disagree, mod_agree, agree, strongly_agree}; assigns 1, 2, 3, 4, 5, 6 to the enumeration constants; enum count {zero, one, two, five = 5, seven = 7, null = 0, once = zero + 1, twice, thrice,}; assigns 0, 1, 2, 5, 7, 0, 1, 2, 3 to the enumeration constants. COMP9021 (Principles of Programming) Notes 5.0: Arithmetic types, constants, printf() 2014 session 1 19 / 36 Constants that represent natural numbers What has been said about constants that represent integers applies mutatis mutandis to constants that represent natural numbers, except that u or U is added after the digits in the representation, with unsigned added to the names of the types. For instance, 1u and 1U are of type unsigned int . 1lu , 1lU , 1Lu , 1LU , 1ul , 1uL , 1Ul , 1UL are of type unsigned long . 0XFUL is of type unsigned long , and represents the natural number 15. COMP9021 (Principles of Programming) Notes 5.0: Arithmetic types, constants, printf() 2014 session 1 20 / 36
Image of page 5

Subscribe to view the full document.

Constants that represent real numbers (1) The syntactic form of constants that represent real numbers is depicted in float.pdf Examples of such constants are 1.56E+12 2.87e-3 3.14159 .2 4e16 .8E-5 100. Again, a leading a + or - sign is interpreted as an operator; hence in particular, no constant represents a negative real number. COMP9021 (Principles of Programming) Notes 5.0: Arithmetic types, constants, printf() 2014 session 1 21 / 36 Constants that represent real numbers (2) A constant of this kind can fit into a double , in which case it is of type double , or be too big or too small to fit into a double but not too big or too small to fit into a long double , in which case it is of type long double , or be too big or too small to fit into a long double , in which case something happens that we happily ignore. Moreover, a constant of this kind can be suffixed with f or F , in which case it is of type float if it fits in a float , of type double if it does not fit in a float but fits in a double , and of type long double if it does not fit in a double but fits in a long double , or be suffixed with l or L , in which case it is of type long double if it fits in a long double . COMP9021 (Principles of Programming) Notes 5.0: Arithmetic types, constants, printf() 2014 session 1 22 / 36 Constants that represent characters (1) There are four ways to represent a character by a constant of type int . By putting the character between single quotes, except for a number of characters such as the new line character, the single quote or the backslash. By using the decimal value of the code of the character. By putting single quotes around a backslash followed by the octal value of the code of the character.
Image of page 6
Image of page 7
  • Fall '19
  • 11

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

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes