题解 | #获取字符串长度#

获取字符串长度

https://www.nowcoder.com/practice/9a2d212d23f5436c80607d5e68c6d12a

#include <iostream>
using namespace std;

//函数
//int GetStrL

int main() {

    char str[100] = { 0 };
    cin.getline(str, sizeof(str));

    // write your code here......
    char *p =str;//地址指向字符串起始位置
    while(*p != '\0')//P加到末尾的位置
        p++;
    printf("%d",p-str);//两个相同类型指针相减得到字符串长度


    return 0;
}


全部评论

相关推荐

11-06 16:50
门头沟学院 Java
用微笑面对困难:word打字比赛二等奖的我,也要来凑合凑合
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务