Type Conversion, Type Aliases and Type Deduction Flashcards

1
Q

Implicit type conversion

A

is performed when one one data type is expected, but a different data type is supplied

If the compiler knows how to convert, it will. Otherwise you get a compile error

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

Name three standard conversions

A

numeric promotion, numeric conversions and arithmetic conversions

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

numeric promotion

A

is the conversion of smaller numeric types to larger numeric types e.g. int to double

includes integral and floating point promotions

are value preserving

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

value preserving

A

no loss of value or precision

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

numeric conversion

A

a type conversion between fundamental types that isn’t a numeric promotion

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

narrowing conversion

A

type of numeric conversion that may result in the loss of value or precision

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

usual arithmetic conversions

A

rules applied when operands of different types are provided to binary operators

e.g. 5.5 + 5; => 5.5 + 5.0;

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

explicit type conversion

A

performed when programmer explicitly requests conversion via a cast

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

2 types of casts you should do in c++

A

static casts and dynamic casts

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

static cast

A

it provides compile-time type checking and only allows conversions that are considered safe by the compiler

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

dynamic cast

A

Another type of casting operator used for casting pointers or references to classes up and down the class inheritance hierarchy.

It’s primarily used for performing safe downcasting (casting from a base class pointer or reference to a derived class pointer or reference) and for performing runtime type checking.

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

typedefs / type aliases
Show code example

A

allow programmer to create an alias for a data type

e.g. using Degrees = double;

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

auto keyword for type uses

A

can be used to do type deduction, this drops const and references

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