+ 2

Why the return statement only take integer ,why it can't take char as char has also a ascii value which is also a integer.

11th Oct 2018, 2:45 PM
Ankita Sinha
Ankita Sinha - avatar
2 odpowiedzi
+ 2
Or you can convert the char to int: int bla() { char a = 'a'; return (int)a; }
11th Oct 2018, 4:36 PM
Anna
Anna - avatar
+ 1
If you could mix it all up with no consequences, why would you have types in the first place? With a char, the stored integer will be interpreted as a letter. If you want to return a char, you can just make the return value char: char myfunc(int) {...}
11th Oct 2018, 4:24 PM
HonFu
HonFu - avatar