实现strlen()函数,strcmp()函数 const知识点
1、strlen()函数的实现:
#include<stdio.h>intstrLen(char*str);intstrLen(char*str){inti=0;while(*str){str++;i++;}returni;}voidmain(void){char*str="abcdefg";intlength;length=strLen(str);printf("%d\n",length);}
2、strcmp()函数的实现:
#include<stdio.h>intstrCmp(char*str1,char*str2);intstrCmp(char*str1,char*str2){while(*str1==*str2&&*str1&&*str2){str1++;str2++;}return*str1-*str2;}voidmain(void){char*str1="hello";char*str2="hell";printf("%d\n",strCmp(str1,str2));}
3、const的用法:
const只读。
(1)const int a = 100 <=> int const a = 100; a空间是只读空间,a空间的值不能更改。
(2)const int *a; <=> int const *a; *a的值不能改变,a指针变量的值可以更改。
int* const a; *a的值可以更改,a指针变量只读,不能改其值
const int* const a; *a, a 均只读空间,其值不可更改!
const离谁进,修饰谁,谁就不可更改!!!
注意:刚开始用Linux进行编程:
(1). Linux下64位与32位的区别:
int都是4字节的。64位下,long 8字节, 指针 8字节
(2).Linux下注释块:#if 0(注释) 1(不注释)
...........
#endif
(3).gcc -c 只编译不连接 gcc .c -o 目标文件 编译和连接
(4).objdump -d test(可执行文件) > x86 反汇编文件查看X86内容。
编译结果往往与平台,编译器关系很大!!!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。