我想通过一个函数来执行下面的代码。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
char* string = "hello_World";
string++;
printf("%s\n", string);
// ignore memory leak for sake of quiz
return 0;
}
输出:
ello_World
现在,我尝试将指针的引用传递给一个函数,然后递增它,而不是在 main
中递增指针。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void myfunc(char** param){
param++;
}
int main(){
char* string = "hello_World";
myfunc(&string);
printf("%s\n", string);
return 0;
}
但输出是 hello_World
能否请您告诉我我编写的代码中发生了什么以及如何更改它以获得所需的结果?
最佳答案
您将指针递增到指针,您需要 (*param)++;
https://stackoverflow.com/questions/64354819/