'Why an Int32 variable can't be assigned to an Int64 variable or vice versa in Swift?

I could not assign Int32 var/let to Int64 var/let or vice-versa in Swift. I get a compile time error when I attempt to do so. What is the reason behind this ?



Solution 1:[1]

I can offer the solution of your problem in C++.

#include <iostream>
#include <vector>
#include <algorithm>
void showContentVector(std::vector<int>& input)
{
    for(int i=0; i<input.size(); ++i)
    {
        std::cout<<input[i]<<", ";
    }
    return;
}
void minimumDigit(int number, int& minimum, std::vector<int>& input)
{
    if(number==0)
    {
        minimum=input[0];
        for(int i=1; i<input.size(); ++i)
        {
            minimum=std::min(minimum, input[i]);
        }
        return;
    }
    input.push_back(number%10);
    minimumDigit(number/10, minimum, input);
    return;
}
int main()
{
    std::vector<int> inputVector;
    int minimumNumber;
    minimumDigit(52873, minimumNumber, inputVector);
    std::cout<<"minimumNumber <- "<<minimumNumber<<std::endl;
    return 0;
}

Here is the result:

minimumNumber <- 2

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vadim Chernetsov