棘手的问题.... [英] Scratchy question....

查看:58
本文介绍了棘手的问题....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用单个返回

语句返回两个字符指针,或者使用单个返回

语句返回两个值。例如,假设我们有一个类似的函数 -


char * abc()/ *这个函数是否写得好???任何问题

* /

{

char def [8] =" chump";

return( char *)def;

}


void main()

{

char * g ,h,* i;

g = abc();

h = * g;

i = somefunction(g); / *****这将是否有任何问题

行******* /

}


现在是时候抓头了......

是否可以返回第二个字符指针以使用

这个功能..... ie我们可以更改函数abc()返回

一个函数中相同字符类型的另一个指针

调用.... ?????????? ????????????


另外,abc()函数是否写得好> ????我们可以获得的任何错误
在某些情况下
?????

Is it possible to return two character pointers using a single return
statement or for that matter returning two values using a single return
statement. For example, say if we have a function like -

char* abc() /*Is this function well written??? any problems
*/
{
char def[8]= "chump";
return (char*)def;
}

void main()
{
char *g,h,*i;
g =abc();
h =*g;
i = somefunction(g); /*****WILL THERE BE ANY PROBLEMS IN THIS
LINE*******/
}

Now time to scratch heads...
Is it possible to return a second character pointer to use back from
this function.....i.e. can we change the function abc() to return
another pointer of same character type in one function
call....???????????????????????

Also, is the abc() function well written>????any errors that we can get
under some circumstances?????

推荐答案



ch ******* @ yahoo.com 写道:
是否可以返回两个字符指针使用单个返回
语句或者使用单个返回
语句返回两个值。例如,假如我们有一个像 -

char * abc()/ *这个函数是否写得好???任何问题
* /
{char def [8] =" chump" ;;
return(char *)def;


您正在尝试返回本地变量的地址,该函数可能在函数返回时不存在
!!

}

void main()
{*> char * g,h,* i;
g = abc();
h = * g;
i = somefunction(g); / *****这个问题会出现在这个问题上吗******* /



在这里你试图用它不存在的地址由

传递给另一个函数!


你期望发生什么?试着想一想

- 拉维

}现在是时候抓头了......
是否有可能返回第二个字符指针从
这个函数中使用..... ie我们可以改变函数abc()返回
另一个同一个字符类型的指针在一个函数中调用.... ????????????????? ?????

另外,abc()函数编写得好> ????我们可以在某些情况下得到的任何错误?????
Is it possible to return two character pointers using a single return
statement or for that matter returning two values using a single return
statement. For example, say if we have a function like -

char* abc() /*Is this function well written??? any problems
*/
{
char def[8]= "chump";
return (char*)def;
You are trying to return the address of a ''local variable'' which might
not exist upon the function return !!
}

void main()
{
char *g,h,*i;
g =abc();
h =*g;
i = somefunction(g); /*****WILL THERE BE ANY PROBLEMS IN THIS
LINE*******/

and here you are trying to use that non-existant address by
passing it to another function !

What do you expect to happen btw ? Try to think about it
- Ravi
}

Now time to scratch heads...
Is it possible to return a second character pointer to use back from
this function.....i.e. can we change the function abc() to return
another pointer of same character type in one function
call....???????????????????????

Also, is the abc() function well written>????any errors that we can get
under some circumstances?????






尝试执行以下代码,您可以找到大部分时间22打印的b
。我想它会回答你的第一个问题。

int * s()

{

int a = 20;

返回& a;

}


int sum()

{

int z = 22;

返回0;

}


int main()

{

int * ptr = s();

sum();

printf("%d",* ptr);

}

2)发送第二个Char ptr,将其作为参数发送给func所以

chimple .....

Try executing the below code you can find that most of the time 22 is
printed. I think it will answer your first question.
int *s()
{
int a=20;
return &a;
}

int sum()
{
int z=22;
return 0;
}

int main()
{
int *ptr = s();
sum();
printf("%d",*ptr);
}
2) To send the second Char ptr, send it as the argument to the func So
chimple.....


嗯....我运行代码并且运行良好....我的意思是我得到了答案

''c' '如同'笨蛋' - 当我使用printf("%c",h)时,def []数组;答案

是''c''...我明白可能有一个案例,当本地数组

在函数外面不可用时....我认为你是对的......

Well....I ran the code and it worked well....I mean I got the answer
''c'' as in "chump" - def[] array when I use printf("%c", h); The answer
was ''c''...I understand that there might be a case when the local array
is not available outside the function.... I think you are correct....


这篇关于棘手的问题....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆