Reputation: 31
if my c code is
#include<stdio.h>
int main()
{
int c;
while((c=getchar())!=EOF)
{
putchar(c);
}
getch();
return 0;
}
I want to know whether int c woud be converted into char , or the input character would be converted into int and then be stored in c.
Upvotes: 2
Views: 120
Reputation: 17605
The return type of getchar
is int
, so no type conversion takes place in the assignment.
Upvotes: 3
Reputation: 30489
getchar
returns an int
and putchar
expects an int
so there is no need of conversion. char
in name may be confusing for you. But type int
also allows to accommodate some special values for ex: EOF
Upvotes: 6
Reputation: 134326
From the man page of getchar()
int getchar(void);
So, why'd think of conversion, anyway? The return type of getchar()
is int
, being stored into an int
variable.
Same goes for putchar()
also.
int putchar(int c);
Upvotes: 5