首页 > 其他分享 >memset,allocate,sizeof,strlen,strcpy,strcat

memset,allocate,sizeof,strlen,strcpy,strcat

时间:2022-10-08 11:25:05浏览次数:44  
标签:int memset strcat char strcpy printf sizeof strlen array

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main() {
    // typedef struct Node{
    //     int data;
    //     struct Node* p;
    // }Node, *pNode;
    int array_i[1024];
    printf("%d\n", sizeof(array_i) / sizeof(int));
    char array_c[1024];
    printf("%d\n", sizeof(array_c));

    //字符指针
    char* p = "hello";
    printf("%s\n", p);
    char p2[] = "world";
    printf("%d\n", sizeof(p2)); //自带'0'
    printf("%d\n", strlen(p2)); //不带'0',strlen不管有没有'0',只计算长度,不包括0
    char p3[] = { '1','2' };
    printf("%d\n", sizeof(p3)); //不带'0'
    //strlen 在计算长度的时候不会把结束符 '\x00' 计算在内,strcpy 在拷贝的时候会把 '\x00' 也算上,所以就会造成 off by one
    char p4[1024];
    memset(p4, 1, sizeof(p4));
    printf("%d\n", p4[0]);

    char p5[1024] = "string1";
    char p6[] = "string2";
    strcat(p5, p6);
    for (int i = 0; i < 20; i++)
        printf("%c", p5[i]);
    printf("\n%d", strlen(p5));

    //strcpy

    return 0;
}

 

 

标签:int,memset,strcat,char,strcpy,printf,sizeof,strlen,array
From: https://www.cnblogs.com/iGhost/p/16768345.html

相关文章

  • 关于 memset
    简要\(\texttt{memset}\)原用处是初始化\(\texttt{char}\)用的,故是按\(\texttt{1}\)个字节为单位初始的。但现在也用于数组。用法memset(数组名字,值,sizeof数组......
  • 快速理解memset
    memset函数是在头文件:cstring 或 memory中 memset函数的作用是将数字以单个字节逐个拷贝的方式放到指定的内存中去memset(a,0,sizeofa);int类型的变量一般占......
  • memset函数的赋值问题
    memset函数的赋值问题memset函数的定义在C++标准库中对memset函数的定义为:定义于头文件cstring。转换值ch为unsignedchar并复制它到dest所指向对象的首count......
  • C语言字符串处理函数 strcat()和strncat()的区别及使用
    字符串函数(Stringprocessingfunction)也叫字符串处理函数,指的是编程语言中用来进行字符串处理的函数。本文主要介绍C语言中符串处理函数strcat()和strncat()的区别使用......