constants
TRANSCRIPT
![Page 1: constants](https://reader030.vdocuments.net/reader030/viewer/2022020208/55b3e135bb61ebfb218b46f9/html5/thumbnails/1.jpg)
![Page 2: constants](https://reader030.vdocuments.net/reader030/viewer/2022020208/55b3e135bb61ebfb218b46f9/html5/thumbnails/2.jpg)
Integer Real Character String
![Page 3: constants](https://reader030.vdocuments.net/reader030/viewer/2022020208/55b3e135bb61ebfb218b46f9/html5/thumbnails/3.jpg)
Decimal integer◦ Consist of 0 through 9, +, -
Octal integer◦ Consist of 0 through 7, with a leading 0
Hexadecimal integer◦ Consist of 0 to 9, and a through f preceded by
0x or 0X
![Page 4: constants](https://reader030.vdocuments.net/reader030/viewer/2022020208/55b3e135bb61ebfb218b46f9/html5/thumbnails/4.jpg)
The largest integer value is machine-dependent
Qualifiers◦ U or u: unsigned integer◦ l or L: long integer ◦ UL or ul: unsigned long integer◦ Short integer
![Page 5: constants](https://reader030.vdocuments.net/reader030/viewer/2022020208/55b3e135bb61ebfb218b46f9/html5/thumbnails/5.jpg)
short is no longer than int and that long is no shorter than int.
![Page 6: constants](https://reader030.vdocuments.net/reader030/viewer/2022020208/55b3e135bb61ebfb218b46f9/html5/thumbnails/6.jpg)
Example2.1 Representation of integer constants on a 16-bit computer.
#include<stdio.h>main(){
printf("Integer values\n\n");printf("%d %d %d\n",32767,32767+1,32767+10);printf("\n");printf("Long integer values\n\n");printf("%ld %ld %ld\n",32767L,32767+1L, 32767+10L);
}
![Page 7: constants](https://reader030.vdocuments.net/reader030/viewer/2022020208/55b3e135bb61ebfb218b46f9/html5/thumbnails/7.jpg)
(1) decimal point◦ Consist of 0 through 9, . ,+ , -◦ 3.14159, .94 , -.58 , +1.234
(2)Exponential notationmantissa e exponent
◦ .56e3 2.3e-3 -2.3E-3◦ The exponent must be an integer number
Suffixes f or F indicate a float constant L or l indicate a long double “Default values of constants” on page35
![Page 8: constants](https://reader030.vdocuments.net/reader030/viewer/2022020208/55b3e135bb61ebfb218b46f9/html5/thumbnails/8.jpg)
Floating-Point Round-off Errors Take a number, add 1 to it, and subtract the
original number. What do you get? You get 1. A floating-point calculation, may give another answer:
![Page 9: constants](https://reader030.vdocuments.net/reader030/viewer/2022020208/55b3e135bb61ebfb218b46f9/html5/thumbnails/9.jpg)
A character enclosed within ‘ ’◦ ‘6’ ‘=‘ ‘;’ ‘ ‘◦ Character constants have integer values, For
example◦ ‘a’ and 97◦ ‘0’ and 48
Backslash character constants◦ Table2.5 on page28◦ ‘\ooo’ and ‘\xhh’
![Page 10: constants](https://reader030.vdocuments.net/reader030/viewer/2022020208/55b3e135bb61ebfb218b46f9/html5/thumbnails/10.jpg)
a sequence of characters enclosed in “ ”, for example◦ “hello” “34” “+()” “x” “\n”
“x” and ’x’
![Page 11: constants](https://reader030.vdocuments.net/reader030/viewer/2022020208/55b3e135bb61ebfb218b46f9/html5/thumbnails/11.jpg)
A variable is data name that may be used to store a data value.◦ Variable names correspond to locations in the
computer's memory◦ Every variable has a name, a type, a size and a
value◦ Whenever a new value is placed into a variable, it
replaces (and destroys) the previous value◦ Reading variables from memory does not change
them
![Page 12: constants](https://reader030.vdocuments.net/reader030/viewer/2022020208/55b3e135bb61ebfb218b46f9/html5/thumbnails/12.jpg)
The declaration of variables must be done before they are used.
declaration formdata-type v1,v2,…,vn;
for example◦ int count;◦ float sum;◦ double ratio;◦ char ch;
![Page 13: constants](https://reader030.vdocuments.net/reader030/viewer/2022020208/55b3e135bb61ebfb218b46f9/html5/thumbnails/13.jpg)
To initialize a variable means to assign it a starting, or initial, value.
In C, this can be done as part of the declaration.
char ch=‘ ’; int cows = 32, int dogs, cats = 94;