zoukankan      html  css  js  c++  java
  • 面试题

    #include<iostream>
    #include<STRING>
    using namespace std;
    int main()
    {
       char *src = "hello world";
       char * dest = NULL;
       int len = strlen(src);
       //cout<<len<<endl;
       dest = (char *)malloc(len);
       char *d =dest;
       char * s =src[len];
       while (len--!=0)
       {
        d++ = s--;
        cout<<dest;
       }
       return 0; 
    }

    改正后的

    #include<iostream>
    using namespace std;
    int main()
    {
       char *src = "hello world";
       char * dest = NULL;
       int len = strlen(src);
       dest = (char *)malloc(len);
       char *d =dest;
       char * s = &(src[len]);//*S此时为 '\0'

       len = len + 1;
       while ( len--!= 0)
        *d++ = *s--;     //这里要循环Len + 1次
       
       len = strlen(src);
       for (int i =0; i<=len - 1; i++)  //将d还原
        d--;
       cout<<"d="<<d<<endl;

       return 0; 
    }

    输出结果 为  hello world 的反转

     参考 strcopy 的写法,也可以这样写

      while ((*d++ = *s--) != *src)
       NULL; 

  • 相关阅读:
    ng-repeat高级用法
    使用 CSS3 实现超炫的 Loading(加载)动画效果
    ADO.NET访问数据库
    连接查询和分组查询
    T-SQL数据查询基础
    使用SQL语句操作数据
    使用表组织数据
    SQL Sever数据库
    使用属性升级Mybank
    C# 语法
  • 原文地址:https://www.cnblogs.com/chengxin1982/p/1378645.html
Copyright © 2011-2022 走看看