the cherno Flashcards

(23 cards)

1
Q

What is this an example of?
#include <iostream></iostream>

A

preprocessor statement

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

What does this do?
#include <iostream></iostream>

A

Copy paste the declarations from iostream.h at the top of the file

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

How does compilation work in C++? Describe all of the steps.

A
  1. Process preprocessor statements
  2. Compile all (or selected) files to .obj binaries
  3. Linker will combine all .obj files into one .exe or .dll
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Give an example of a linker error.

A

A function or type is declared in a header or other declaration, but no definition could be found in the .obj files.

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

1 bit

A

a 0 or a 1

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

1 byte

A

8 bits

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

How many unique values can be stored in 10 bytes?

A

10 bytes = 80 bits = 2^80 unique combinations = 2^80 unique values

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

How to find out what the size of a given primitive type is

A

sizeof(int)

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

True or false: the size of a long is always the same, regardless of your computer and your compiler.

A

false! it may differ for different compilers

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

what is the function of the different primitive data labels?

A

size, and clues for the programmer and language about how to treat it (i.e. when printing)

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

Float vs double

A

float = 4 bytes, double = 8 bytes

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

To assign a float, you must…

A

add f to the end of the numeric literal

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

*var

A

deref the pointer “var” (i.e. access the value)

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

int*

A

declare a pointer (and we want to treat the value at the address llike an int, but there is no guarantee that it will be one)

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

char&

A

declares a reference (a wrapper for a pointer that gets one address in its lifetime)

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

&var

A

access the address of the value var

17
Q

NULL

A

equivalent to 0

18
Q

Why is this ok?
char* myPtr = &someChar; cout << myPtr << "\n";

A

char* pointers are treated specially be cout; it will automatically dereferenace it and get the associated char

19
Q

bool

A

a 1-bit integer. if it is 0, it is fasle, otherwise it is true

20
Q

What will happen when this code is run?
int a = 5;
int b = 8;
int& ref = a;
ref = b;

A

it will set the value at the address of a to 8. it will NOT change where the pointer points.

21
Q

memset args

A

memset(address, value, size_of_block)

22
Q

write a method to take in a int pointer, and increment the value that it points to

A

void increment(int* ptr)
{
(*ptr)++;
}

23
Q

write a method to take in an int by reference, and increment the value

A

void increment(int& i)
{
i++;
}