Code: #include <stdio.h> char buffer[4]="AAA"; //char buffer[4]={'A','A','A','A'}; void main() { printf("0x%02X\n", *buffer); // (1) it does not work printf("0x%02X\n", (char *) *buffer); // (2) fixed variant } If array "buffer" is char array and we try to use it by pointer (1) then compiler make wrong code without any warning. We may fix it as wrote (2). Using of int array makes right code. For details you may see asm-code generated by compiler. For line (1) compiler does not generate code "ld b,0".
Comment from translator: Do not use %X with char data in printf/sprintf. You need convert char to int before:
int i = *buffer; printf("0x%02X\n", i);
|