- 博客(4)
- 收藏
- 关注
原创 typedef与结构类型中一种变量命名方法辨析
typedef是重新定义一种数据类型,并不创建这个结构类型下的变量数据。而在结构类型中如代码二中的变量定义方式,此变量所属的类型依然为union,并在union的数据名创建了一个union的变量。#include<stdio.h>//代码一typedef union { int i; char ch[sizeof(int)];//不同编译环境int类型所占字节数不同,故用sizeof。 } LIANHE;//LIANHE即为union类型,但不是变量。int main(){
2021-09-05 17:17:33
89
原创 将结构体传入函数中的两种办法(整体传入与指针传入对比)
#include<stdio.h>struct date{ int a; int b;}one;struct date* get(struct date* p);void out(struct date* p);int main(){ struct date* p=&one; get(p); out(p);}struct date* get(struct date* p){ scanf("%d %d",&p->a,&p->b);.
2021-08-27 11:58:05
5492
原创 在字符串处理中strlen()与sizeof()的区别
首先声明的是strlen()为字符串函数,而sizeof()为运算符。由于char类型只占一个字节,故在字符串处理中也可用它来大致测量字符串的长度,甚至在某些分配内存空间的场景中,可以直接用char* a=(char*)malloc(sizeof(a));代替char* b=(char*)malloc(strlen(a)+1);来缩短编程时间;char* a=(char*)malloc(sizeof(a));//也可写为: char* b=(char*)malloc(strlen(a)+1);.
2021-08-19 10:35:41
159
原创 关于i++与++i的再次理解
#include<stdio.h>int mylen(const char* s){ int i=0; while(s[i]!='\0'){ i++; } return i;}int main(){ char word[]="hello"; printf("%d",mylen(word));}在这个自编strlen函数(mylen)中,如果将自编块中return i;改为i++或++i,会出现两种不同的结果,分别为:return ++i → 返回值为6;..
2021-08-13 12:30:51
415
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人