C++ Basics Flashcards

1
Q

What is

int a = 5;

called

A

Copy assignment

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

Default initialization

A

int x;

Not advised as in most cases, leaves variable with indeterminate value

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

Copy initialization

A

int x = 5;

Not advised as doesn’t do any validation

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

Direct initialization

A

int x (5);

Not advised as doesn’t do any validation

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

Direct list initialization

A

int x {5};

Preferred as disallows narrowing conversions

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

Copy list initialization

A

int x = {5};

Preferred as disallows narrowing conversions

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

Value initialization

A

int x{};

Usually performs zero initialisation

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

What is preferred assignment or initialisation and why?

A

initialisation is preferred because it means variables won’t have indeterminate values if we access them before assignment which could result in undefined behaviour

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

std::endl

A

outputs a newline character and flushes any pending output to the console

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

‘\n’

A

outputs a newline character and lets system decide when to flush pending output to the console

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