Wise Owl Wise Owl - 1 month ago 4
C Question

Why is char a = 65 less portable than char a = 'A'

I've just asked this question What is the reason for the double negation -(-n)? where the answerer mentions in a comment that

char a = 'A';

is more portable than

char a = 65;

Why is this? Surely they are exactly the same?


A is represented by 65 in ASCII; but that doesn't mean that every character system will represent it by 65.

If you write

char a = 65;

then you're implicitly assuming that the system will be using ASCII. That's less portable than writing

char a = 'A';

which doesn't make that assumption.