Knowee
Questions
Features
Study Tools

What is the return type of the getchar function in C?

Question

What is the return type of the getchar function in C?

🧐 Not the exact question you are looking for?Go ask a question

Solution

The return type of the getchar function in C is int. This might seem a bit strange since you'd expect it to return a char, but there's a good reason for this. The getchar function returns the next character from the standard input (stdin). However, it needs to be able to represent two kinds of output: any possible character and an end-of-file (EOF) indicator.

Since a char type in C isn't big enough to represent all possible characters and EOF, the function returns an int. This allows it to return any possible character as its ASCII value and EOF (which is typically -1) as well.

This problem has been solved

Similar Questions

VariablesWhat is the return type of getchar()?

What is the default return-type of getchar()?a.charb.Intc.char *d.reading character doesn’t require a return-type

What is the return type of the function printf in C?intvoidcharfloat

What is the return type of the puts function in C?

What is the use of getchar()?a.The next input character each time it is calledb.EOF when it encounters end of filec.The next input character each time it is called EOF when it encounters end of filed.None of the mentioned

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.