W2 P1: Fundamental Types Flashcards
Name the three integer types
Standard integers - either signed or unsigned
booleans
chars
Ranges of signed and unsigned ints
signed - negative and positive values
unsigned - no negative values
5 standard integer types:
signed char short int int long int long long int
How many bytes does a signed char occupy?
1
How many bytes does a short int typically occupy?
2
How many bytes does an int typically occupy?
4
How many bytes does a long int typically occupy?
4
How many bytes does a long long int typically occupy?
8
How to define constants for
signed chars, ints, long ints, and long long ints:
signed char - single quotes around the value
ex.
signed char k, m, n, p;
k = ‘[’; // character
m = ‘\133’; // octal - note the leading \
n = ‘\x5b’; // hexadecimal - note the leading \x
p = ‘\X5B’; // hexadecimal - note the leading \X
int
ex.
a = 91; // decimal
b = 0133; // octal - note the leading 0
c = 0x5b; // hexadecimal - note the leading 0x
d = 0X5B; // hexadecimal - note the leading 0X
long int - suffix of L or l
ex.
long int a, b, c, d;
a = 91L; // long: L or l
b = 0133L; // octal - long: L or l
c = 0x5bL; // hexadecimal - long: L or l
d = 0X5BL; // hexadecimal - long: L or l
long long int - suffix of LL or ll
ex.
long long int a, b, c, d;
a = 91LL; // long: LL or ll
b = 0133LL; // octal - long: LL or ll
c = 0x5bLL; // hexadecimal - long: LL or ll
d = 0X5BLL; // hexadecimal - long: LL or ll
Integer types ranges:
signed char -128 - 127
short int <= -32,768 - >= 32,767
int -2,147,483,648 - 2,147,483,647
long int <= -2,147,483,648 - >= 2,147,483,647
long long int <=-9,223,372,036,854,775,808 - >= 9,223,372,036,854,775,807
Define constants for unsigned types:
use the suffix U or u
ex.
unsigned int g;
unsigned long int h;
unsigned long long int k;
g = 0x5bU; // unsigned int: U or u
h = 0X5BUL; // unsigned long: (U or u) and (L or l) any order
k = 456789012345ULL; // unsigned long long: (U or u, LL or ll) any order
Ranges for unsigned integer types:
unsigned char 0 255
unsigned short int 0 >=65,535
unsigned int 0 4,294,967,295
unsigned long int 0 >= 4,294,967,295
unsigned long long int 0 >= 18,446,744,073,709,551,615
How many bytes does a bool typically occupy?
1
How many bytes does a float typically occupy?
4
How many bytes does a double typically occupy?
8