随笔分类 -  c语言

摘要:#include<stdio.h> #include<string.h> //使用匿名结构体嵌套 struct person1 { const char* name; char gender[20]; struct { int age; }; }p1; //不使用匿名结构体嵌套 struct pho 阅读全文
posted @ 2020-04-06 20:17 Axuanup 阅读(989) 评论(0) 推荐(0)
摘要:#include<stdio.h> #include<string.h> /* struct 类型名 { 类型 变量名; 类型 变量名; }tpye_name1,tepy_name2; //tpye_name1,tepy_name2为具体变量名,使用时无需再声明结构体了 */ struct Game 阅读全文
posted @ 2020-04-06 18:22 Axuanup 阅读(238) 评论(0) 推荐(0)
摘要:#include<stdio.h> //tpyedef 关键字有什么用,我们每次使用结构体的时候,都要加,struct 这个关键字 //使用tepydef 关键字我们给struct关键字给定义个别名,这样我们定义的时候就不用加struct 这个关键字了 /* 定义方式 typedef struct 阅读全文
posted @ 2020-04-06 18:08 Axuanup 阅读(536) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 3 //结构体关键字struct 4 //定义一个游戏玩家的NPC 5 struct Gamer 6 { 7 char cName[24]; //玩家名称 8 int nHealth; //生命值 9 int nMagic; //魔法 10 int nSk 阅读全文
posted @ 2020-04-06 17:41 Axuanup 阅读(966) 评论(0) 推荐(0)
摘要:#include<stdio.h> int strlen(char* p);//获取字符串的长度 void strcpy(char* des, char* src); //字符串拷贝 char strcat(char* des, const char* stc); //字符串拼接 //字符串拷贝 v 阅读全文
posted @ 2020-04-06 17:06 Axuanup 阅读(236) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 void loop_a(void); 3 void loop_b(void); 4 void loop_c(void); 5 void loop_d(void); 6 7 8 void loop_a() 9 { 10 int i = 0; 11 while 阅读全文
posted @ 2020-04-03 23:09 Axuanup 阅读(260) 评论(0) 推荐(0)
摘要:#include <stdio.h> int main(int argc, char *argv[]) { int x = 2; int y = x; int* p1 = &x; int* p2 = p1; printf("只拷贝值,不拷贝地址\n"); printf("深拷贝:x = %p,val 阅读全文
posted @ 2020-04-03 22:40 Axuanup 阅读(167) 评论(0) 推荐(0)
摘要:int arr[5] = {1,2,3,4,5}; int *p = arr; for(int i = 0; i < 5;i++) { arr[i] = 表示数组元素0 *(p+i) = 表示指针元素0 *p+i = 表示指针元素0 p[i] = 表示指针元素0 p++ = 表示指针元素0 } 阅读全文
posted @ 2020-04-03 22:37 Axuanup 阅读(728) 评论(0) 推荐(0)
摘要:#include<stdio.h> int main(void) { int arr[] = { 1, 2, 3, 4, 5, 6 }; //arr数组名本身就是一个指针 int *p = arr; //int *p = &arr[0]; //和int *p = arr; 是等价的 for (int 阅读全文
posted @ 2020-04-03 22:36 Axuanup 阅读(320) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 int main(void) 3 { 4 int arr[] = {1,2,3,4,5,6,7,8}; 5 int i; 6 for(i = 0;i < sizeof(arr)/sizeof(arr[0]);i++) 7 { 8 printf("arr[% 阅读全文
posted @ 2020-04-03 22:33 Axuanup 阅读(3954) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 void swap1(int a,int b); //利用异或交换变量的值,值传递 3 void swap2(int* a,int* b); //利用异或交换变量的值,地址传递,这里用指针* 4 5 6 void swap1(int a,int b) /* 阅读全文
posted @ 2020-03-30 21:59 Axuanup 阅读(549) 评论(0) 推荐(1)