W2 P1: Fundamental Types Flashcards

1
Q

Name the three integer types

A

Standard integers - either signed or unsigned

booleans

chars

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Ranges of signed and unsigned ints

A

signed - negative and positive values

unsigned - no negative values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

5 standard integer types:

A
signed char
short int
int
long int
long long int
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How many bytes does a signed char occupy?

A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How many bytes does a short int typically occupy?

A

2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How many bytes does an int typically occupy?

A

4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How many bytes does a long int typically occupy?

A

4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How many bytes does a long long int typically occupy?

A

8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to define constants for

signed chars, ints, long ints, and long long ints:

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Integer types ranges:

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Define constants for unsigned types:

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Ranges for unsigned integer types:

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How many bytes does a bool typically occupy?

A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How many bytes does a float typically occupy?

A

4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How many bytes does a double typically occupy?

A

8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How many bytes does a long double typically occupy?

A

8

17
Q

Four ways to initialize a variable

A

int n0 = 7; // C-style
int n1 = 7.2; // C-style - narrowing - loss of information

int n2 {6}; // universal form braces-enclosed list

int n3 = {5}; // = is redundant

18
Q

What is the recommended way to initialize variables?

A

Universal form - brackets enclosed

ex.
int x {6};

19
Q

What does the keyword auto do?

A

Infers the type from the previously declared object

ex.
int a[] {1, 2, 3, 4, 5, 6};
const auto n = 6;

20
Q

explain the alignof() operator

A

Returns the alignment requirement of its argument type.

An alignment requirement represents the number of bytes between successive addresses of objects of a given type.

ex. cout &laquo_space;alignof(int);
Output: 4

21
Q

explain the alignas() operator

A

Sets the alignment requirement to the number specified