I'm struggling to understand how the numbers in ascii-1 start at 65. Does the computer know that A is equal to 65? Shouldn't int start at 0?

Heres my code:


int main(void){
    for(char c = 'A'; c<= 'Z'; c++){
        printf("%i is %c\n", (int)c, c);

Thanks, hope you can help!


the ASCII values do not start at 65. ASCII (short for American Standard Code for Information Interchange) is just an agreed-upon standard for representing letters, digits, symbols, etc with numbers since numbers are the only thing that computers can understand.

it's just that people happened to agree on the letter 'A' to correspond to the value 65, 'B' to correspond to 66, and so on. and the short answer is yes, the computer knows that 65 maps to 'A', 66 maps to 'B', etc.

try the following

printf("%c\n", 65);

the previous code outputs A to the standard out (the terminal window naturally) because printf was instructed to interpret the integer value 65 as a character (through the %c format specifier), hence, mapped to A.

see https://www.youtube.com/watch?v=UPlR4eMMCmI for more on ASCII!

and not sure what you mean by "ints starting at 0". a signed int variable is capable of representing values from -2^31 - 1 to 2^31 - 1 on a typical 32-bit machine.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .