Explicit type conversion in c language

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

Answers (3)

Codor
Codor

Reputation: 17605

The return type of getchar is int, so no type conversion takes place in the assignment.

Upvotes: 3

Mohit Jain
Mohit Jain

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

Sourav Ghosh
Sourav Ghosh

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

Related Questions