chipp wrote: |
---|
ok. but what i mean is, what happened inside the program when it tried to convert argv to char |
Nowhere in your program do you try to convert
argv to char.
At line 7, you try to convert
argv[1] to a char. That is a different thing, and it's important to understand that.
What happens is:
-
argv[1] is a char*, i.e. it is a pointer, i.e. it is an integer. Any pointer is just an integer, and the value of that integer is interpreted as a memory address.
- we convert that integer to a char. A char is also an integer, but only an 8-bit one, that can hold a value in the range 0 - 255. The value is interpreted as an ASCII code representing a single character. So, the integer that is potentially bigger than 255, is truncated to a value that can fit into an 8-bit integer, from 0 - 255.
- when that integer value is output using cout, it is inerpreted as an ASCII code. The character that is shown on your screen is the character represented by that code.