33,311
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include "iostream"
using namespace std;
void fun(char* buf)
{
buf += 2;
}
int _tmain(int argc, _TCHAR* argv[])
{
char buf[1024] = "123";
fun(buf);
printf("%s\n",buf);
getchar();
return 0;
}
char buf[1024] = "123";
char *p = buf;
fun(p); //修改指针
printf("%c\n",*p);
#include <iostream>
using namespace std;
char* fun(char *buf)
{
buf += 2;
return buf;
}
int main()
{
char buf[1024]="123";
char *b= fun(buf);
cout<<b<<endl;
return 0;
}
#include "stdafx.h"
#include "iostream"
using namespace std;
void fun(char** buf) //修改指针
{
*buf += 2;
}
int _tmain(int argc, _TCHAR* argv[])
{
char buf[1024] = "123";
fun(&buf); //修改指针
printf("%s\n",buf);
getchar();
return 0;
}
#include "stdafx.h"
#include "iostream"
using namespace std;
void fun(char*& buf) //引用传值
{
buf += 2;
}
int _tmain(int argc, _TCHAR* argv[])
{
char buf[1024] = "123";
fun(buf);
printf("%s\n",buf);
getchar();
return 0;
}