69,373
社区成员
发帖
与我相关
我的任务
分享
//版本(1)
#include <stdio.h>
#include <conio.h>
char *Msg="HELLO";
void ChMsg(char *&message){
//
//你这是将message指向了Msg,然后又将message给赋上NULL
//函数返回,message消失,但是并没有影响到Msg
//
message=NULL;
Msg=message;//添加这句OK了;
}
int main(){
ChMsg(Msg);
if(!Msg)
printf("change ok");
else
printf("sorry");
getch();
return 0;
}
//版本(2)
#include <stdio.h>
#include <conio.h>
char *Msg="HELLO";
void ChMsg(char *&message){
//
//你这是将message指向了Msg,然后又将message给赋上NULL
//函数返回,message消失,但是并没有影响到Msg
//
message=NULL;
}
int main(){
ChMsg(Msg);
if(!Msg)
printf("change ok");
else
printf("sorry");
getch();
return 0;
}
//版本(3)
#include <stdio.h>
#include <conio.h>
char *Msg="HELLO";
void ChMsg(char **message){
//
//你这是将message指向了Msg,然后又将message给赋上NULL
//函数返回,message消失,但是并没有影响到Msg
//
message=NULL;
}
int main(){
ChMsg(&Msg);
if(!Msg)
printf("change ok");
else
printf("sorry");
getch();
return 0;
}
///给你写了3个样本
//楼主你再看下,10L的没有错误。
#include"stdio.h"
char *Msg="HELLO";
void ChMsg(char **message)
{
*message=NULL;
}
int main()
{
ChMsg(&Msg);
if(!Msg)
{
printf("change ok\n");
}
else
{
printf("sorry\n");
}
return 0;
}
#include <stdio.h>
#include <conio.h>
char *Msg="HELLO";
void ChMsg(char* message){
//
//你这是将message指向了Msg,然后又将message给赋上NULL
//函数返回,message消失,但是并没有影响到Msg
//
message=NULL;
Msg=message;//添加这句OK了;
}
int main(){
ChMsg(Msg);
if(!Msg)
printf("change ok");
else
printf("sorry");
getch();
return 0;
}
#include <stdio.h>
#include <conio.h>
char *Msg="HELLO";
void ChMsg(char* message){
//
//你这是将message指向了Msg,然后又将message给赋上NULL
//函数返回,message消失,但是并没有影响到Msg
//
message=NULL;
Msg=message;//添加这句OK了;
}
int main(){
ChMsg(Msg);
if(!Msg)
printf("change ok");
else
printf("sorry");
getch();
return 0;
}
void ChMsg(char *&message)//函数改变的是指针的副本,改为传指针的引用
{
message=NULL;
}