memset()函数及其作用
发布日期:2021-05-12 14:27:09 浏览次数:19 分类:精选文章

本文共 1623 字,大约阅读时间需要 5 分钟。

1.Buffers���������

  • **void memset(void s, int c, size_t n)

  • ������������:

    • s: ������������������������������
    • c: ���������������������������ASCII������������
    • n: ���������������������
  • ������:

    char str[100];
    memset(str, '0', sizeof(str));

2.������������������������������

  • ���������:

    struct sample_struct {
    char csName[16];
    int iSeq;
    int iType;
    };
    struct sample_struct stTest;
    memset(&stTest, 0, sizeof(struct sample_struct));
  • ������:

    struct sample_struct TEST[10];
    memset(TEST, 0, sizeof(struct sample_struct) * 10);

3.I���m not shure������������

  • ������:

    • ���������������:
      char a[5];
      memset(a, '1', 5);
    • ���������������:
      int a[5];
      memset(a, 1, 5);
  • ���:

    • ������1: ���������������������'1'���������������ASCII������1������������������������������������������1������������int���������������������4���������������������������memset������������������������������������1���������������������������������������������������������������������������������������������������������������������������������
    • ������2: ���������������������������memset������������
      int a[5];
      memset(a, 0, sizeof(int)*5);

4.���������������

  • ���������������:

    char arr[10];
    memset(arr, '\0', sizeof(arr));
  • ������������������:

    struct MyStruct {
    int A;
    char B[5];
    } obj;
    memset(&obj, 0, sizeof(struct MyStruct));

5.������������

  • ���������:

    • ������n������������������������n <= strlen(s)������������������������������
    • ������������sizeof������������������������
  • ������:

    • ������������������������������������������������������������memset������������������������
  • ���������:

    • ���snprintf������������strcpy���memcpy���������������������������������������������
上一篇:htons(), htonl(), ntohs(), ntohl()详解
下一篇:Socket的accept函数解析

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2025年04月04日 09时58分11秒