任何人都可以解釋這段代碼中發生了什麼嗎?C字符串和十六進制字符
#include <stdio.h>
void f(const char * str) {
printf("%d\n", str[4]);
}
int main() {
f("\x03""www""\x01""a""\x02""pl");
f("\x03www\x01a\x02pl");
return 0;
}
爲什麼輸出是?以十六進制指定
1
26
'\ x01a'是'26' – BLUEPIXY
因爲在這些字符串中的第五位字符具有的ASCII值'1'和'26'。 –
使用'printf(「%s」,str)'來打印一個字符串。 – ouah