Complete the code to convert the integer 10 to a float.
int a = 10; float b = [1]; std::cout << b << std::endl;
Use static_cast<float>(a) to convert integer a to float safely in C++.
Complete the code to cast a double to an integer using C-style cast.
double pi = 3.14159; int x = [1]; std::cout << x << std::endl;
int(pi) which is a functional-style cast instead of C-style.C-style cast (int)pi converts the double pi to an integer by truncating the decimal part.
Fix the error in the code by correctly casting a void pointer to an int pointer.
void* ptr = nullptr;
int* iptr = [1];
std::cout << iptr << std::endl;dynamic_cast which only works with polymorphic types.Use reinterpret_cast<int*>(ptr) to convert a void* to int* safely in C++.
Fill both blanks to create a map from string lengths to strings, filtering only strings longer than 3 characters.
std::map<int, std::string> length_map; for (const auto& word : words) { if (word.[1] > 3) { length_map[static_cast<int>(word.[2])] = word; } }
word.length() inconsistently.Use word.size() to get the length and length() to compare string length in C++.
Fill all three blanks to create a vector of floats from a vector of ints by casting each element.
std::vector<int> nums = {1, 2, 3, 4};
std::vector<float> floats;
for (auto [1] : nums) {
floats.push_back([2]);
}
float first = floats[[3]];Use num as the loop variable, cast it with static_cast<float>(num), and access the first element with index 0.