1

Hello im trying to understand why i can't cast type int To a char using a user defined function with parameters.

Im following along with learncpp. And i am a beginner, So please could i have the simplified versions.

If i create a user function, And try a return the value back it will just output the integer instead of an ASCII character.

Here is my following code.

int ascii(int y)
{
    return static_cast<char>(y);
}

int main()
{
    std::cout << ascii(5) << std::endl;
    return 0;
}

1 Answers1

1

The issue is the type of your return value. It should be a char. Not an int

char ascii(int y)
{
    return static_cast<char>(y);
}
jpr42
  • 718
  • 3
  • 14