已知strcpy 的函数原型:char *strcpy(char
*strDest, const char *strSrc)其中strDest 是目的字符
串,strSrc 是源字符串。不调用C++/C 的字符串库
函数,请编写函数strcpy。
以下与库函数strcpy(char *p, char *q)功能不相等的程序段是()。A.strcpy1(char *p, char *q){ while ((*p++=*q++)!='\0')}B.strcpy2( char *p, char *q){ while((*p=*q)!='\0'){p++ q++}}C.strcpy3(char*p, char *q){ while (*p++=*q++)}D.strcpy4(char *p, char *q){ while(*p)*p++=*q++}
点击查看答案
补充完整下面的类定义:class XCH{char*a;public:XCH(char*a A) { //构造函数a=new char[strlen(aA) +1];strcpy(a,aA) ;}XCH&operator=(const XCH&x){//重载赋值函数delete[ ]a;a=new char[strlen(x.A) +1];strcpy(a,x.A) ;______;}~XCH( ){delete[ ]a;}};
请编写能直接实现char * strcpy(char * pstrDest,const char * pstrSource)函数功能的代码。
有如下程序:#includeusing namespace std;class Book{public:Book(char*t=””){strcpy(title,t);}private:char title[40];};class Novel:public Book{public:Novel(char *t=””):Book(t){}char*Category()const{return”文学”;)};int main(){Book *pb;pb=new Novel();coutCategory();return 0;}若程序运行时输出结果是“文学”,则划线处缺失的语句是A.char*Category();B.char*Category()const;C.virtual char*Category()const;D.virtual char*Category()const=0;
void setmemory(char **p, int num){ *p=(char *) malloc(num);}void test(void){ char *str=NULL;getmemory(&str,100);strcpy(str,"hello");printf(str);}运行test函数有什么结果?( )
输入二个 64 位的十进制数,计算相乘之后的乘积已知 strcpy 函数的原型是:char * strcpy(char * strDest,const char * strSrc);1.不调用库函数,实现strcpy 函数。2.解释为什么要返回char *。
void Test(void){char *str = (char *)malloc(100); strcpy(str, “hello”); free(str); if(str != NULL) { strcpy(str, “world”); printf(str);}}请问运行 Test 函数会有什么样的结果?