Question:
Can a C function have character return type? AND if so why "getch()" has "int" return type not "char"?
Sheer
2012-07-12 07:32:26 UTC
I know a function in C can have void,int or float return types.But can it have "char" return type? If not,then if we return a character, for example return('*') then is the ASCII value of the character returned?And also, if not, then is the ASCII of the character accepted by getch() returned as an integer or it returns something else?I mean, does it return 0 or 1 as error-free or non error-free execution of getch()?

And if a function in C can have char return type, then how come getch() has integer return type?
Three answers:
TheMadProfessor
2012-07-12 07:53:18 UTC
When you get right down to it, a char variable type IS an int type...just one using a single byte of storage and with the domain of allowable values severely limited.
peteams
2012-07-12 08:23:36 UTC
You can return a char from a function, but chars are always promoted to ints in expressions. So returning a char is pretty much the same as returning an int.



While most implementations of getch() will have no special return values, it belongs to a family that will return special values for end-of-file and error conditions. These values are normally negative impossible char values.



[Also I suspect the getch() your using is not returning ASCII, it is much more likely to be returning UTF-8 or ANSI (which in turn is a misnomer for ISO 8859 extensions). This matters if people are likely to type things like # which is not in every ASCII version or € which I believe is not in any.]
?
2016-12-08 20:10:41 UTC
I had 2 miscarriages in 2007 my husband and that i never informed all of us i replaced into pregnant so whilst it did ensue we basically had to handle it ourselves. regrettably i replaced into admitted to scientific institution with the 2d miscarriage as they theory it may be ectopic and my husband had to tell his ***** mom as we necessary somebody to shield our son. She replaced into crying and saying properly she might desire to have popular i replaced into pregnant (i replaced into basically 5 weeks and in basic terms found out myself) my own mom didnt even comprehend. some days later we went round her homestead and she or he introduced that my husbands cousin replaced into pregnant and she or he had informed her mom immediately away, couldnt care much less approximately my emotions and the actuality identification in basic terms lost a infant. Then a pair of month later we went out for my FIL birthday and because shed had a drink she introduced all of it up approximately how she might desire to have popular and how it made her experience not as quickly as did she ask how i replaced into or how I felt. My husband and that i attempted to tell her that none of it replaced into approximately her whether it doesnt remember what that's she continually turns it around so its approximately her she must be centre of interest. She is a chain smoker and smokes on an analogous time as my son is ingesting or on an analogous time as hes sat on her knee. She supplies him crisps and chocolates whilst she knows hes going to have his tea at homestead. She is particularly a terrible individual who I might desire to publish with for my husband.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...