What are the values โ€‹โ€‹of * cast * and * conversion *?

Possible duplicate:
Is there a difference between type and type conversion?

I personally use the terms "casting" and "conversion" interchangeably. It's right? If not, what is the difference?

+3
source share
4 answers

The conversion entails building a type A from an instance of another type B.

Casting entails the use of one or more diverse casting operators in C ++ or casts in the style of C.

+3
source

I donโ€™t think they are the same - casting forces the compiler to perform an explicit conversion, but you can also have implicit conversions, for example.

double d = 23; // implicit conversion from int to double

Versus:

int i = static_cast<int>(23.0); // explicit conversion from double to int
+3

, . : ", ". , , .

0

- . - , , atoi itoa, . :

int minutes_to_seconds(int minutes) { return minutes * 60; }
0

Source: https://habr.com/ru/post/1774572/


All Articles