如何"而(* S ++ = * T ++)QUOT;复制一个字符串? [英] How does "while(*s++ = *t++)" copy a string?

查看:125
本文介绍了如何"而(* S ++ = * T ++)QUOT;复制一个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,这是什么code做的(由<一个href=\"http://www.joelonsoftware.com/articles/CollegeAdvice.html\">http://www.joelonsoftware.com/articles/CollegeAdvice.html):

My question is, what does this code do (from http://www.joelonsoftware.com/articles/CollegeAdvice.html):

while (*s++ = *t++);

该网站说,code以上副本的字符串,但我不明白为什么...

the website says that the code above copies a string but I don't understand why...

它有指针呢?

推荐答案

这是等同于这样的:

while (*t) {
    *s = *t;
    s++;
    t++;
}
*s = *t;

当了炭牛逼指的是'\\ 0',while循环将终止。在此之前,它会复制 T 指向的字符是取值指向,然后增加焦炭取值 T 来指向他们的阵列中的下一个字符。

When the char that t points to is '\0', the while loop will terminate. Until then, it will copy the char that t is pointing to to the char that s is pointing to, then increment s and t to point to the next char in their arrays.

这篇关于如何&QUOT;而(* S ++ = * T ++)QUOT;复制一个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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