C++ interview Flashcards

(9 cards)

1
Q

What is a statement?

A
  • The smallest independent unit of computation in c++
  • Similar so sentences in natural language
  • Usually ends with a semicolon
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How is memory usually accessed in c++?

A

Through objects. Direct memory access is discouraged.

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

What is the difference between definition and initialisation?

A

Definition creates a space in memory for the variable according to its data type

Initialisation assigns a value to the variable at the moment of its creation

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

What are the different forms of initialisation?

A

traditional:
- copy initilization: initial value after equal sign => int a = 5;
- direct initialisation: initial value in parenthesis => int a (5);

modern:
- direct-list-initialisation: initial value in braces => int a {7};
- value-initialisation: empty braces => int a {};

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

With default initialisation, what is the value of the variable?

A

The variable is not initialised and contains garbage value

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

What is the modern way to initialise variable in c++?

A

Direct list initialization, the use of curly braces

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

What is disallowed with direct list initialisation?

A

Narrowing conversion are disallowed and the compiled is required to produce and error

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

What is the value of a variable after value initialisation?

A

The variable is initialised to the equivalent of zero for its data type

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

What variable attribute allows us to not get a warning if a variable is unused?

A

[[maybe_unused]]

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