请问这个C复制功能退出其循环? [英] How does this C copy function exit its loop?

查看:125
本文介绍了请问这个C复制功能退出其循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void copy (char *source, char *dest) {
    while (*dest++ = *source++);
}

这是重新通过 psented $ P $的字符*源复制到外地 * DEST 点。对于下一个迭代,每个字符指针指向下一个字段在内存中,是正确的?

The char that is represented by *source is copied to the field *dest points to. For the next iteration, each char pointer points to the next field in memory, is that correct?

在没有这个循环实际上停下来?我能想到的唯一条件是,有没有剩余内存空间,但随后的函数必须以一个错误终止,不应该吗?

When does this loop actually stop? The only condition I can think of is that there's no space left in memory, but then the function must terminate with an error, shouldn't it?

我完全新的C,所以请原谅我的简单的问题。

I'm completely new to C, so forgive me the simple questions.

推荐答案

字符是整型。积分类型间preTED如下面的方式条件语句:

chars are integral types. Integral types are interpreted as conditionals in the following way:

 0 -> false
 Anything else -> true

由于弦,在C是空值终止(即 0 '\\ 0'),当它到达它停止该字符串的结尾。

Since "strings" in C are null-terminated (meaning 0 or '\0') when it reaches the end of the string it stops.

这篇关于请问这个C复制功能退出其循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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