What's the return type and argument of putchar()

194 views Asked by At

I see that return type of putchar() is int,

int putchar(int char)

but

for(i=65;i<91;i++)
putchar(i);

gives output ABC...... How?Shouldn't it return int?

Plus, it turns out that I can use character in argument too.How?

1

There are 1 answers

0
Barmar On

You're not printing the return value. To print the return value, assign the result to another variable, and print that.

for (i = 65; i < 91; i++) {
    int ret = putchar(i);
    printf("\nputchar return value = %d\n", ret);
}

The output of this will be:

A
putchar return value = 65
B
putchar return value = 66

and so on up to Z and 90.

65 is the ASCII character code for the letter A. putchar() sends the character code to the terminal, which displays the corresponding character.