So, to express the value 50 in base 8 in C, which is equivalent to the value 40 in decimal, the notation 050 is used. In that case, the remaining digits of the value must be valid base-8 digits and, therefore, must be 0–7. If the first digit of the integer value is a 0, the integer is taken as expressed in octal notation-that is, in base 8. Two special formats in C enable integer constants to be expressed in a base other than decimal (base 10). (So, the value 12,000 is not a valid integer constant and must be written as 12000.) No embedded spaces are permitted between the digits, and values larger than 999 cannot be expressed using commas. The values 158, −10, and 0 are all valid examples of integer constants. A minus sign preceding the sequence indicates that the value is negative. In C, an integer constant consists of a sequence of one or more digits. If i is 10, the expression is equal to 125, but if i is 200, the expression is equal to −65. Would not represent a constant expression because its value would change based on the value of i. But if i were declared to be an integer variable, the expression 128 7 – i Is a constant expression because each of the terms of the expression is a constant value. Expressions consisting entirely of constant values are called constant expressions. The character string "Programming in C is fun.\n" is an example of a constant character string. For example, the number 58 represents a constant integer value. In C, any number, single character, or character string is known as a constant. These one-or-the-other choices are also known as binary choices. Variables of this type are used for indicating an on/off, yes/no, or true/false situation. Finally, the _Bool data type can be used to store just the values 0 or 1. The char data type can be used to store a single character, such as the letter ’a’, the digit character ’6’, or a semicolon (’ ’) (more on this later). The double type is the same as type float, only with roughly twice the precision. A variable declared to be of type float can be used for storing floating-point numbers (values containing decimal places). The C programming language provides four other basic data types: float, double, char, and _Bool. As you will recall, a variable declared to be of type int can be used to contain integral values only-that is, values that do not contain decimal places. You have already been exposed to the C basic data type int. Basic math operators and arithmetic expressions.
0 Comments
Leave a Reply. |