将字符串的第一个字节递增1

tca*_*chy 0 c string pointers

我有一个main程序:

int main() {
    char *str = "hello";
    printf("%s\n", str);
    /* Shift first byte 1 to get "iello" */

    /* Have tried
    str[0] >>= 8; */
    printf("%s\n", str);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

基本向上串的第一字节偏移的字节从去helloielloHelloIello

Yu *_*Hao 5

您无法修改字符串文字,将其更改为:

char str[] = "hello";   //not string literal
printf("%s\n", str);
str[0]++;              //add 1 to the first element
printf("%s\n", str);
Run Code Online (Sandbox Code Playgroud)