-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathA03-integer-types-1.c
55 lines (45 loc) · 1.65 KB
/
A03-integer-types-1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
/*
From the GNU gcc reference manual:
* The 32-bit int data type can hold integer values
in the range of −2,147,483,648 to 2,147,483,647.
You may also refer to this data type as signed
int or signed.
* The 32-bit long int data type can hold integer
values in the range of at least
−2,147,483,648 to 2,147,483,647.
(Depending on your system, this data type might
be 64-bit, in which case its range is identical
to that of the long long int data type.)
You may also refer to this data type as long,
signed long int, or signed long.
* The 16-bit short int data type can hold integer
valuesin the range of −32,768 to 32,767.
You may also refer to this data type as short,
signed short int, or signed short.
* The 16-bit unsigned short int data type can
hold integer values in the range of 0 to 65,535.
You may also refer to this data type as unsigned
short.
From https://en.wikipedia.org/wiki/Integer_overflow:
Since an arithmetic operation may produce a result
larger than the maximum representable value,
a potential error condition may result. In the
C programming language, signed integer overflow
causes undefined behavior, while unsigned integer
overflow causes the number to be reduced modulo a
power of two, meaning that unsigned integers
"wrap around" on overflow.
Note:
65538 in binary is 10000000000000010
*/
int main(){
int a = 65538;
long int b = 65538;
unsigned short c = 65538;
short int d = 65538;
printf("%d\n", a);
printf("%ld\n", b);
printf("%d\n", c);
printf("%d\n", d);
}