1、字符串结束空字符 与 0 与字符‘0’ 区别
ASCII码表,不出意外,你看到的第一个是空字符(Null),这个对应的就是 ‘\0’ ,其在ASCII码表中对应的是值是0。此外,在判断字符串是否结束的标志时,就是通过判断是否遇到了 ‘\0’ ,如果遇到则表示字符串结束。
而字符 ‘0’ 对应的ASCII码值是48。
参考链接:https://blog.csdn.net/hcxddd/article/details/117880021
2、关于 *p++ 分别作为左值,右值,左右值的操作(C/C++)
#include "stdio.h"
#include "stdlib.h"
int main()
{
char array[114] = {1,2,3,4};
char a[5] = {1,2,3,4};
char * p = array;
char * p2 = a;
printf("*******************************\r\n");
printf("array_add = %#x\r\n",array);
printf("p_add = %#x\r\n",p); //两个地址相同
while(1)
{
//*p++ = 20;
//*p2 = *p++; //等价于 *p2 = *p, p++; 先赋值,地址再+1
*p++ = 20; //等价于 *p =20,p++; 先赋值,地址再+1
//printf("*******************************\r\n");
//printf("p2_add = %d\r\n",*p2);
//printf("p_add = %#x\r\n",p);
printf("p = %d\r\n",array[0]);
printf("p = %d\r\n",*p);
system("pause");
}
return 0;
}
可参考:https://blog.csdn.net/qq_33826564/article/details/81880554
3、非全局变量的指针地址累加
u32 get32bitValue(u8 **str)
{
u32 value;
printf("str1 = %#x\n",*str);
memcpy(&value, *str, 4);
*str += 4;
printf("str1 = %#x\n",*str);
printf("value = %s\r\n",&value);
return value;
}
void main()
{
u8 * package="23";
printf("str = %#x\n",package);
get32bitValue(&package);
printf("str = %#x\n",package);
//printf("s = %s\n",s);
system("pause");
}
/***********运行结果*************/
str = 0x42401c
str1 = 0x42401c
str1 = 0x424020
value = 23
str = 0x424020
请按任意键继续. . .
4、结构体数组(数组名)地址+1,和数组结构体元素地址的区分
typedef struct
{
//u8 *next;
u8 num1;
u8 num2;
u8 num3;
}TEST_HNB;
void main()
{
// u8 * package="23";
TEST_HNB A[10];
puts("第一批地址:\r\n");
printf("&(A[0].num1) = %#x\n",&(A[0].num1));
printf("&(A[0].num2) = %#x\n",&(A[0].num2));
printf("&(A[0].num3) = %#x\n",&(A[0].num3));
printf("&(A[0].num1)+1 = %#x\n",&(A[0].num1)+1);
printf("A[0] = %#x\n",&A[0]);
printf("地址A = %#x\n",A);
printf("A[1] = %#x\n",&A[1]);
printf("A[2] = %#x\n",&A[2]);
printf("A[3] = %#x\n",&A[3]);
printf("A[4] = %#x\n",&A[4]);
puts("第二批地址:\r\n");
printf("A+0 = %#x\n",A+0);
printf("A+1 = %#x\n",A+1);
printf("A+2 = %#x\n",A+2);
printf("A+3 = %#x\n",A+3);
printf("A+4 = %#x\n",A+4);
//get32bitValue(&package);
//printf("str = %#x\n",package);
//printf("s = %s\n",s);
system("pause");
}
运行结果:
第一批地址:
&(A[0].num1) = 0x19ff10
&(A[0].num2) = 0x19ff11
&(A[0].num3) = 0x19ff12
&(A[0].num1)+1 = 0x19ff11
A[0] = 0x19ff10
地址A = 0x19ff10
A[1] = 0x19ff13
A[2] = 0x19ff16
A[3] = 0x19ff19
A[4] = 0x19ff1c
第二批地址:
A+0 = 0x19ff10
A+1 = 0x19ff13
A+2 = 0x19ff16
A+3 = 0x19ff19
A+4 = 0x19ff1c
请按任意键继续。。。
5、按字符个数拼接到字符串上
```c
typedef struct
{
u8 * string;
u32 size;
u32 length;
}CString;
CString * str = 通过malloc动态内存分配n个byte,用完记得free(string);
appendStringWithChar(str,"ABC",3) //将3个字符ABC增加到字符串首地址str上;
int appendStringWithChar(CString *string , const char *str, const int length)
{
for(int i = 0; i < length ; i++)
{
*(string->string + string->length ++ ) = *(str + i);
}
}
6、isdigit函数、tolower函数、log函数
调用的c库函数isdigit(ch)检测字符ch是否为0~9的字符,
tolower(ch)返回ch该字符的对应的小写字母字符,非小写则返回原值;
#include “ctype.h”
#include “math.h”
//e =2.718281828459;
printf("value = %f\r\n",log(2.718281828459*2.718281828459));
输出 :value:2.000000
printf("value = %f\r\n",log(2.718281828459*2.718281828459*2.718281828459));
输出 :value:3.000000
结果为以e为底的运算值;
7、转义字符 斜杠 \ 输出处理
#include "stdio.h"
#include "stdlib.h"
void main()
{
char a[20] = "\"woshi\"";
char b[20] = "\'woshi\'";
char c[20] = "\\woshi ";
char d[20] = "\woshi ";
puts(a);
puts("\r\n");
puts(b);
puts("\r\n");
puts(c);
puts("\r\n");
puts(d);
puts("\r\n");
system("pause");
}
执行结果:
"woshi"
'woshi'
\woshi
woshi
请按任意键继续. . .
8、持续更新。。。