This is some sample code from The C Programming Language by Ritchie & Kernighan.
int c;
while((c=getchar())!=EOF) {
putchar(c);
}
Notice that putchar referes to a variable of type int. Why is it possible to return and display both characters and integers with this code?
An
intis usually represented by 4 bytes while acharis actually just 1 byte of data. You can easily store a full character and more in the singleintthatgetchar()returns. When an int is passed toputchar(int)it just lops off the extra space before displaying it. This technique is useful for passingEOFwhich is actually not acharat all, but anintthat signals the end of the file.