题解 | #获取字符串长度#
获取字符串长度
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道真题和解析