Discussion 1: C++ Refresher Flashcards

1
Q

preprocessor directives

A

top of file with a #, processed before the compiler, #include, #define, (#ifdef, #ifndef, #endif), #pragma once

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

include

A

include replaces the directive with the content of the specified header or file

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

define (

A

define replaces all instances of identifier with replacement.

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

ifdef, ifndef, and #endif

A

identifiers allows sections to be complied if an identifier is/isnt defined

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

pragma once

A

makes source file to be included only once in a single compilation

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

char

A

1 byte | primitive type

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

std::string( char array )

A

char array

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

int (How many bytes, range)

A

4 bytes | -2.147 bil - 2.147 bil

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

unsigned int (How many bytes, range)

A

4 bytes | 0 to 4.294 bil

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

long (how many bytes, range)

A

8 bytes | -910^18 to 910^18

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

unsigned long (bytes, range)

A

8 bytes | 0 to 18*10^18

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

double (bytes, use case)

A

8 bytes | used for decimals

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

float (bytes, use case)

A

4 bytes | used for decimals

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

float vs double

A

float uses 4 bytes , double uses 8 bytes.
Use case: double is more precise

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

bool

A

1 byte | True or False

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

void

A

0 bytes | function not returning anything

17
Q

std::string( char array ) vs std::string

A

std::string(char array) is an array of characters while string is not

18
Q

auto (keyword)

A

derives the type of a variable on the fly

19
Q

decltype (keyword)

A

derives the type of variable by using another variable

20
Q

pointers

A

variable whose value is the memory address of another variable

21
Q

pointer (syntax)

A

*

22
Q

Address-of Operator

A

& | gets the memory address of a variable

23
Q

Dereference Operator

A
  • | gets the value at the memory address of a pointer
24
Q

pointer of array

A

points at the first element of the array

25
Q

array vs vector

A

array is just a pointer to its first elements. It has no knowledge of where it ends

26
Q

new (keyword)

A

dynamically allocates memory in the heap, and returns a pointer

27
Q

delete (keyword)

A

used to deallocate heap memory. delete or delete[] , pointer is not destroyed but the item the pointing is referencing is.

28
Q

memory leak

A

dynamic memory (heap) that is no longer being referenced and not deleted

29
Q

passing into functions in c++

A

pass by pointer, or reference, if not it will create a copy of passed in argument

30
Q

structs vs class

A

both create object, structs are public by default, while class is private by default

31
Q

templates

A

used when we don’t know the type it will receive. usually used at very low level

32
Q

T o F: (Templates) We can write one template function that can be used for all data types including user defined types. Like sort(), max(), min(), etc

A

TRUE

33
Q

T o F: (Templates) We can write one template class or struct that can be used for all data types including user defined types. Like LinkedList, Stack, Queue, etc…

A

TRUE

34
Q

T o F: (Templates) Templates are an example of overriding

A

FALSE

35
Q

const

A

variable is NOT allowed to change

36
Q

What is mutable? int* const x

A

the memory address is locked, but the int value can change

37
Q

What is mutable? const int* x or int const * x

A

The int cannot change, but the memory address can be changed.

38
Q

What is mutable? const int * const x

A

The int and memory address cannot be changed.

39
Q

const objects, can only be called by

A

const functions