这是什么,而(* P2 ++ = * P1 ++);意思?

编程入门 行业动态 更新时间:2024-10-25 06:31:02
本文介绍了这是什么,而(* P2 ++ = * P1 ++);意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个code座:

int main () { char *p1 = "Hello"; char *p2; p2 = (char*)malloc (20); memset (p2, 0, 20); while (*p2++ = *p1++); printf ("%s\n", p2); }

但我无法解释该行的工作而(* P2 ++ = * P1 ++);你可以让我知道这个操作公式中的顺序?

But I can not explain the working of the line while (*p2++ = *p1++); Could you let me know the order of operation in this formula?

推荐答案

这是经典的C code试图把一切在一行看起来非常聪明。

It's classic C code trying to look extremely clever by putting everything in one line.

而(* P2 ++ = * P1 ++); 等同于

strcpy(p2, p1); p1 += strlen(p1) + 1; p2 += strlen(p2) + 1;

在换句话说,它拷贝一个空值终止字符串, P1 结束了指向源字符串的结束和 P2 指向目标字符串的结尾。

In other words, it copies a null-terminated string, with p1 ending up pointing to the end of the source string and p2 pointing to the end of the destination string.

更多推荐

这是什么,而(* P2 ++ = * P1 ++);意思?

本文发布于:2023-08-01 04:21:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1265169.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:这是什么

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!