First of all, please excuse me for asking this question because there are already dozens of similar variations of it. However, I am not entirely sure If I can understand it correctly. So, please let me explain what I managed to understand and correct me if I am wrong.

This is an example from the K&R book:

```
    #include <stdio.h>

    main()
    {
1)      int c;

2) 4)   while ((c = getchar()) != EOF)
3)      putchar(c);
    }

```

So, I understand the above program like this:

*1)* We declare `c` as `int` instead of `char` because using a `char` data type won't always operate correctly and it will eventually mess it up. `Char` data type has variations depending on the system and it could be by default either `signed` [−127, +127] or `unsigned` [0, 255]. Also, `EOF` is not always `-1` by default because it depends on the system and the compiler as well.

* *1.1)* So, if we declare `c` as `char` and it's by default `signed char` on the system then it will still work but it will mess up if we enter a character equal to ASCII 128 and above? **What will happen?** `getchar()` will return a value of maximum possible ASCII value for the selected data type, 127?
* *1.2)* In the opposite, if we declare `c` as `char` and by default is `unsigned char` on the system then `getchar()` will always be **NOT** equal to `EOF` no matter what because we cannot store a negative value, **right?**

Because all of the variations above it's correctly to declare `c` as `int` to avoid a possible conflict?

2) We type some characters as input `c = getchar()` grabs this input and convert it to ASCII number after that it checks to make sure it's not equal to `EOF`.

3) If it is **NOT** equal to `EOF`, it displays the input characters as output.

4) It goes back in a state where we must input new characters to continue the loop.

*Is all above correct?*

*[Additional question]* Also, the statement `getchar() != EOF` will output `1` or `0` as value. `1` value will mean that `getchar()` is **NOT** equal to `EOF`. And `0` as value will shows us that `getchar()` is actually **equal** to `EOF`, right?

*[Additional question]* I saw another question from another user here on Stack Overflow regarding `getchar()` and `char` data type, however, I cannot understand the answer of [Oliver Charlesworth](https://stackoverflow.com/users/129570/oliver-charlesworth).

> 
> Your program doesn't work fine; it won't be able to distinguish
>  between EOF and 255.
> 
> 
> 

What that means? Could you explain it to me? Also, I can't understand what this means too:

> 
> 0 through 7 (# 255) and EOF can be represented as 1111....32
>  times..... (assuming a 4 byte int)? There > will be no conflict here.
> 
> 
> 

[Link to the Oliver Charlesworth's answer.](https://stackoverflow.com/questions/8464030/using-int-for-character-types-when-comparing-with-eof/8464039#8464039)

---

***UPDATE***

Thank you all! Regarding this:

> 
> `0 through 7 (# 255) and EOF can be represented as 1111....32
>  times..... (assuming a 4 byte int)? There > will be no conflict
>  here.`
> 
> 
> 

If I understood it correctly after all the answers and explanations below. That means `EOF` with value `-1` will be represented as `1111 1111` for example and if the data type is `char` then it will think it's #255 because it's only 8 bit and it will be stored in the memory exactly as it is 0xFF (#255) with no other indications (in a few words: data is lost and now instead of value `-1` it means something entirely different), **is that correct?** So, to avoid this confusion, we allocate 4 bytes when we declare the `c` as `int` to make sure no data will be lost and it will store the `EOF` value `-1` in 32 bits like `32 times...1111 1111` including a sign that it's also a negative value. **Do I understand it correctly?**
Thanks once again!