* p = + * q ++的含义 [英] Meaning for *p = +*q++

查看:78
本文介绍了* p = + * q ++的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai,


查看该组的一些查询时,我遇到了一个与strcpy类似的功能

。代码片段如下:


#include< stdio.h>

#include< stdlib.h>


void myfunc(char * p,char * q)

{

while(* p = + * q ++)

* p ++;

}


void main()

{char * str;

char * str1 =" apple";


str = NULL;

str =(char *)calloc(sizeof(str),sizeof(char *)* sizeof(str1));

myfunc(str,str1);


printf(" \ n \t Str:%s \ n \\\ Str1:%s \ n",str,str1);

}


1.这里的功能处理方式如何?

while(* p = + * q ++)

* p ++;


2.另外,我注意到同样的查询也包含相同的功能

可以用其他方式编写如下:


void myfunc(char * p,char * q)

{

while(*(p ++)=(* q)++);

}


但是当我编译我发现没有错误或。


运行时,我遇到应用程序错误的异常。为什么我会这样?
这样做?

请澄清我的疑惑。


谢谢和问候,
M.Sworna Vidhya

Hai,

When viewing some queries of this group, i came across a function
which is similar to strcpy. The snip of the code is as follows:

#include <stdio.h>
#include <stdlib.h>

void myfunc(char *p, char *q)
{
while (*p = +*q++)
*p++;
}

void main()
{ char *str;
char *str1 = "apple";

str = NULL;
str = (char *) calloc (sizeof (str),sizeof (char *) * sizeof(str1));
myfunc(str,str1);

printf("\n\t Str : %s \n\t Str1 : %s \n",str,str1);
}

1. How the functionality process here?
while (*p = +*q++)
*p++;

2. Also, i noticed that the same query also contains the same function
can be written in the other way as follows:

void myfunc(char *p, char *q)
{
while (*(p++) = (*q)++);
}

But when i compile i found no error.

While running, i am getting exception with application error. Why i am
getting so?

Kindly clarify my doubts.

Thanks and Regards,
M.Sworna Vidhya

推荐答案

" sworna vidhya" < SW ************ @ yahoo.co.in>在消息中写道

news:46 ************************** @ posting.google.c om ...
"sworna vidhya" <sw************@yahoo.co.in> wrote in message
news:46**************************@posting.google.c om...
2.另外,我注意到同一个查询也包含相同的功能
可以用其他方式编写如下:

void myfunc(char * p,char * q)
{
while(*(p ++)=(* q)++);
}

但是当我编译我发现没有错误。

运行时,我遇到应用程序错误异常。为什么我这样做?
2. Also, i noticed that the same query also contains the same function
can be written in the other way as follows:

void myfunc(char *p, char *q)
{
while (*(p++) = (*q)++);
}

But when i compile i found no error.

While running, i am getting exception with application error. Why i am
getting so?




您需要使用*(q ++)代替(* q)++。

S



You need to use *(q++) instead of (*q)++.

S


文章< 46 ******************** ****** @ post.google.com>,sworna vidhya写道:
In article <46**************************@posting.google.com >, sworna vidhya wrote:
Hai,

查看该组的一些查询时,我遇到了一个函数
类似于strcpy。代码的片段如下:

#include< stdio.h>
#include< stdlib.h>

void myfunc(char * p,char * q)
{while /(* p = + * q ++)
[ - ]

无用的一元+运算符 - > + * q ++< - 这里。 * p ++;
}


[ - ]

main()无效。 {char * str;
char * str1 =" apple";

str = NULL;
str =(char *)calloc(sizeof(str),sizeof(char *)* sizeof(str1));
[ - ]

无用的强制转换和calloc(sizeof(指向char的指针),

sizeof(指向char的指针)* sizeof(指向char的指针))

也许不是你想要的。 myfunc(str,str1);

printf(" \ n \ str:%s \ n \ str1:%s \ n",str,str1);
}

1.功能如何处理?
while(* p = + * q ++)
* p ++;
[ - ]

就复制而言,它是一种较短的形式...

while(* p = * q) {

p ++;

q ++;

}

....这是一个较短的形式.. 。

* p = * q;

while(* p!=''\ 0''){

p ++;

q ++; * p = * q;

}

....
2.另外,我注意到同样的查询也包含相同的功能
可以用另外的方式写成如下:

void myfunc(char * p,char * q)
{while /(*(p ++)=(* q)+ +);
[ - ]

(* q)++表示在q处增加值。

}

但是当我编译我发现没有错误。
Hai,

When viewing some queries of this group, i came across a function
which is similar to strcpy. The snip of the code is as follows:

#include <stdio.h>
#include <stdlib.h>

void myfunc(char *p, char *q)
{
while (*p = +*q++) [-]
Useless unary "+" operator -> +*q++ <- here. *p++;
}

void main() [-]
main() isn''t void. { char *str;
char *str1 = "apple";

str = NULL;
str = (char *) calloc (sizeof (str),sizeof (char *) * sizeof(str1)); [-]
Useless cast and calloc (sizeof (pointer to char),
sizeof (pointer to char) * sizeof (pointer to char))
probably isn''t what you want, either. myfunc(str,str1);

printf("\n\t Str : %s \n\t Str1 : %s \n",str,str1);
}

1. How the functionality process here?
while (*p = +*q++)
*p++; [-]
It''s a, as far as the copying is concerned, shorter form of ...
while (*p = *q) {
p++;
q++;
}
.... which is a shorter form of ...
*p = *q;
while (*p != ''\0'') {
p++;
q++; *p = *q;
}
....
2. Also, i noticed that the same query also contains the same function
can be written in the other way as follows:

void myfunc(char *p, char *q)
{
while (*(p++) = (*q)++); [-]
(*q)++ means "increment the value at q".
}

But when i compile i found no error.



[ - ]

当然,从语法上来说你写的很好。


干杯,

Juergen


-

\真实姓名:Juergen Heinzl \无火焰/

\私密邮件: ju*****@manannan.org \汇款而非

\图库: www.manannan.org \ /


[-]
Sure, as syntactically what you wrote is fine.

Cheers,
Juergen

--
\ Real name : Juergen Heinzl \ no flames /
\ Email private : ju*****@manannan.org \ send money instead /
\ Photo gallery : www.manannan.org \ /





sworna vidhya写道:


sworna vidhya wrote:

Hai,
<当查看该组的一些查询时,我遇到了一个类似于strcpy的函数
。代码的片段如下:

#include?stdio.h?
#include?stdlib.h?

void myfunc(char * p, char * q)
{while /(* p = + * q ++)
* p ++;
}

void main()


main()返回int,不是void

{char * str;
char * str1 =" apple";

str = NULL;
str =(char *)calloc(sizeof(str),sizeof(char *)* sizeof(str1));


不正确使用calloc(number_of_elements,size_of_each_element)

首先,演员只是隐藏了你没有包含stdlib.h的事实。

其次,args错了。新str数组中元素的数量

可能不是sizeof(str),而是(strlen(str1)+ 1)。

每个元素的大小是char的大小,即1.

myfunc(str,str1);

printf(" \ n \t Str:%s \ n \\ t Str1:%s \ n",str,str1);
}

1.功能如何处理?
while(* p = + * q ++)
* p ++;

2.另外,我注意到同样的查询也包含相同的功能
可以用其他方式编写如下:

void myfunc(char * p,char * q)
{while /(*(p ++)=(* q)++);
^^^^^^

*(q ++)}


myfunc()是strcpy()的实现。

但是当我编译时我发现没有错误。

在运行时,我因应用程序错误而异常。为什么我会这样做?

请澄清我的疑惑。

谢谢和问候,
M.Sworna Vidhya

Hai,

When viewing some queries of this group, i came across a function
which is similar to strcpy. The snip of the code is as follows:

#include ?stdio.h?
#include ?stdlib.h?

void myfunc(char *p, char *q)
{
while (*p = +*q++)
*p++;
}

void main()
main() returns int, not void
{ char *str;
char *str1 = "apple";

str = NULL;
str = (char *) calloc (sizeof (str),sizeof (char *) * sizeof(str1));
improper use of calloc( number_of_elements, size_of_each_element )
First, the cast just hides the fact you have not included stdlib.h.
Second, the args are wrong. The number of elements in the new str array
is probably not sizeof(str), but rather (strlen(str1) + 1).
The size per element is the size of a char, which is 1.
myfunc(str,str1);

printf("\n\t Str : %s \n\t Str1 : %s \n",str,str1);
}

1. How the functionality process here?
while (*p = +*q++)
*p++;

2. Also, i noticed that the same query also contains the same function
can be written in the other way as follows:

void myfunc(char *p, char *q)
{
while (*(p++) = (*q)++); ^^^^^^
*(q++) }
myfunc() is an implementation of strcpy().

But when i compile i found no error.

While running, i am getting exception with application error. Why i am
getting so?

Kindly clarify my doubts.

Thanks and Regards,
M.Sworna Vidhya



-

Fred L. Kleinschmidt

波音助理技术研究员

技术架构师,通用用户界面服务

M / S 2R-94(206)544-5225



--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225


这篇关于* p = + * q ++的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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