当前位置:编程学习 > C/C++ >>

C++代码的含义

#include <iostream.h>
#include <assert.h>

char* StringCopy(char *strDestination,const char *strSource)
{
assert((strDestination != NULL)&&(strSource != NULL));
char *address = strDestination;
while((*strDestination++ = *strSource++) != '\0')
NULL;
return address;
}


哪位大哥能够详细解释一下?
补充:'\0'      是什么意思?
		
答案:
实现字符串strSource到strDestination的拷贝
assert((strDestination != NULL)&&(strSource != NULL));是判断2个指针是否为空,若为空则弹出错误并返回
char *address = strDestination;让address指向strDestination缓冲区的首地址
while((*strDestination++ = *strSource++) != '\0')实现字符串的拷贝,当遇到'\0'时结束拷贝,这里是简单的指针赋值
return address;返回strDestination的首地址
答案补充
C字符串的结束符,凡是char字符串结尾都有一个'\0'

上一个:怎么在界面上用ajax获取struts2中action中的返回值啊??
下一个:C++代码求挑错。

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,