zoukankan      html  css  js  c++  java
  • 字符串

    c语言没有字符串数据类型;使用字符数组来模拟字符串;c语言中的字符串是以‘’为结束符的字符数组。c语言中字符串可以分配于栈空间,堆空间,程序的只读存储区。

    1 char s1[]={'h','e','l','l','o'};
    2 char s2[]={'h','e','l','l','o',''};
    3 char* s3="hello";
    4 char* s4=(char*)malloc(6*sizeof(char));

    char* s3="hello"; 字符串分配于程序的只读存储区,那么s3里面的内容不能更改

    字符串长度:

    第一个‘’字符前的字符个数,即不计算‘’。——strlen(s2);

     1 #include <stdio.h>
     2 int main()
     3 {
     4     char* a="123";
     5     char* b="12345";
     6     if(strlen(b)>=strlen(a))
     7     {
     8         //...........
     9     }
    10     if(strlen(b)-strlen(a)>=0) //总成立
    11     {
    12         //...........
    13     }
    14     
    15     return 0;
    16 }

    面试题:实现库函数strcpy

    内在的趣味,表面的繁琐
  • 相关阅读:
    leetcode 137
    leetcode 134
    133. Clone Graph
    leetcode 131
    leetcode 130
    mac uwsgi ssl issue handler
    leetcode 85 Maximal Rectangle golang
    leetcode 84 golang
    leetcode 61
    C# 后台实现一次上传多个文件
  • 原文地址:https://www.cnblogs.com/data1213/p/4823605.html
Copyright © 2011-2022 走看看