string address
来源:互联网 发布:精英特速读软件 编辑:程序博客网 时间:2024/06/02 01:33
char s1[] = "abcde";
char *s2 = "abcde";
char *s3; s3 = malloc(6); strcpy(s3, "abcde");
char a[100]; strcpy(a,"123");
s1 在stack 的 local var 里面保存 abcde
s2 在stackt的local var里面的s2是一个指针 指向 code segement(里面有abcde)
s3 在stack的local var里面的一个指针 指向 heap里面malloc的位置 malloc申请的地址上 放abcde
s1 = a; 在c里面不能两个array相等 compile error
s2 =a; s2指针指向a的开头
s3=a ok; but memory leak heap里面的abcde没有被释放
strcpy(s1,a); ok 只把从开头 到 \0 copy过去 原来没被覆盖的 保持原样 123\0e\0
strcpy(s2,a); runtime error 把a copy到 s2所指向的地址 而s2所指向地址在read only的 code segment
strcpy是内容的copy
char *s2 = "abcde";
char *s3; s3 = malloc(6); strcpy(s3, "abcde");
char a[100]; strcpy(a,"123");
s1 在stack 的 local var 里面保存 abcde
s2 在stackt的local var里面的s2是一个指针 指向 code segement(里面有abcde)
s3 在stack的local var里面的一个指针 指向 heap里面malloc的位置 malloc申请的地址上 放abcde
s1 = a; 在c里面不能两个array相等 compile error
s2 =a; s2指针指向a的开头
s3=a ok; but memory leak heap里面的abcde没有被释放
strcpy(s1,a); ok 只把从开头 到 \0 copy过去 原来没被覆盖的 保持原样 123\0e\0
strcpy(s2,a); runtime error 把a copy到 s2所指向的地址 而s2所指向地址在read only的 code segment
strcpy(s3,a); ok 把a copy 到heap里面
-------------------------------------------------------------------------------
strcpy是内容的copy
s=a 是 地址的赋值
------------------------------
因为strcpy没有限制要copy多少过去 容易buffer overflow
strcpy strncpy
strcat strncat
sprintf snprintf
get fgets
阅读全文
0 0
- string address
- convert ip address string to unsigned int
- PB高级用法-String(long,"address")
- address
- Address
- address
- address
- address
- address
- Address
- address
- address
- address
- address
- address
- ERROR 1366 (HY000): Incorrect string value: '\xE5\xB8\x82' for column 'address' at row 1
- C language——convert ip address string into uint in linux
- mysql:Incorrect string value: '\xE5\x8C\x97\xE4\xBA\xAC' for column 'address' at row 1
- Struts 2框架下载png、excel等格式的文件
- likely()与unlikely()函数
- 如何查询自己的公网IP
- Linux学习-001
- struts2环境搭建和入门程序
- string address
- 算法提高 ADV-76 GDP计算
- Android最常用而又最难用控件—ListView(二)。
- springboot发送邮件
- 用mysql数据库中的用户名和密码在GUI上实现登陆的功能
- python实现约瑟夫环
- 算法提高 ADV-77 统计平均成绩
- 【Spark2.0源码学习】-8.SparkContext与Application介绍
- hdu 6170 Two strings