Fork me on GitHub

随笔分类 -  C

bilibili.com/video/av80745347
摘要:可以用typedef声明新的类型名来代替已有的类型名。 实例1: #include<stdio.h> #include<iostream> typedef struct { char* name; int age; }STUDENT; int main() { STUDENT stu; stu.na 阅读全文
posted @ 2020-01-01 16:44 西西嘛呦 阅读(710) 评论(0) 推荐(0)
摘要:在c语言中,一般有两种方式来创建字符串 //第一种,利用字符指针 char* p = "hello"; //第二种:利用字符数组 char str[] = "hello"; 那么,它们之间有什么区别呢?以例子说明: #include<stdio.h> #include<iostream> char* 阅读全文
posted @ 2020-01-01 16:19 西西嘛呦 阅读(4815) 评论(0) 推荐(1)
摘要:#include<stdio.h> #include<iostream>#define CORRECT "myfirst" int main() { char str[10]; int func(char* str1, char* str2); printf("输出你最喜欢的:\n"); scanf 阅读全文
posted @ 2020-01-01 15:24 西西嘛呦 阅读(348) 评论(0) 推荐(0)
摘要:#include<typeinfo> using std::cout; int main() { int i; cout << typeid(i).name(); //输出结果为int return 0; } 需要引入头文件:#include<typeinfo> 阅读全文
posted @ 2020-01-01 15:13 西西嘛呦 阅读(6310) 评论(0) 推荐(0)
摘要:#include<stdio.h> #include<iostream> int main() { char* str[10]; printf("请输入:\n"); scanf("%s\n", str); printf("您的输入是:%s\n",str); system("pause"); retu 阅读全文
posted @ 2020-01-01 15:12 西西嘛呦 阅读(3137) 评论(0) 推荐(0)
摘要:1.##:用于拼接操作 实例: #include<stdio.h> #include<iostream> #define CONCAT(parm1,parm2) (parm1##parm2) int main() { int res = CONCAT(1, 2); printf("%d\n", re 阅读全文
posted @ 2020-01-01 15:06 西西嘛呦 阅读(740) 评论(0) 推荐(0)
摘要:1.带参数的宏定义中,宏名和新参表之间不能有空格, 2.在带参数的宏定义中,形参参数不分配内存单元,因此不必作类型定义。而宏调用中的实参有具体值,要用它去代换形参,因此必须作类型说明。 #include<stdio.h> #include<iostream> #define MAX(a,b) (a> 阅读全文
posted @ 2020-01-01 13:51 西西嘛呦 阅读(4594) 评论(0) 推荐(0)
摘要:宏定义只是简单的字符串代换,是在预处理完成的,而typedef是在编译时处理的,它不是作简单的代换,而是对类型说明符进行重新命令。被命名的标识符具有类型定义说明的功能。 #include<stdio.h> #include<iostream> #define PIN1 char* typedef c 阅读全文
posted @ 2020-01-01 11:42 西西嘛呦 阅读(382) 评论(0) 推荐(0)
摘要://定义一个指针变量 int *p; (1)指针可以进行加减一个整数:p++、p--、p+i、p-i、p+=i、p-=i等 (2)将一个变量的地址赋值给指针:int a = 1;p = &a; (3)将数组首元素的地址赋值给指针:int array[3] = {1,2,3};p = array; ( 阅读全文
posted @ 2020-01-01 11:17 西西嘛呦 阅读(1059) 评论(0) 推荐(0)
摘要:定义 含义 int i; 定义整型变量i int* p; p为指向整型数据的指针变量 int a[n]; 定义整型数组a,它有n个元素 int* p[n]; 定义指针数组p,它由n个指向整型数据的指针元素构成 int (*p)[n]; p为指向含n个元素的一维数组的指针变量 int f(); f为返 阅读全文
posted @ 2020-01-01 10:57 西西嘛呦 阅读(837) 评论(0) 推荐(0)
摘要:#include<stdio.h> #include<iostream> int main(int argc,char *argv[]) { printf("参数的个数是(包括第0个当前可执行文件的名字):%d\n", argc); //参数列表,字符串指针 while (*argv) { puts 阅读全文
posted @ 2020-01-01 10:48 西西嘛呦 阅读(1358) 评论(0) 推荐(0)
摘要:定义:int **p; 实例: #include<stdio.h> #include<iostream> int main() { char* str[] = { "hello","hi","nihao" }; char** p; for (int i = 0; i < 3; i++) { //指针 阅读全文
posted @ 2019-12-31 20:13 西西嘛呦 阅读(330) 评论(0) 推荐(0)
摘要:什么是指针数组? 一个数组,里面存放的元素均为指针类型数据,被称为指针数组。 其定义形式? int *name[4]; 基本实例一:利用数组初始化指针数组 #include<stdio.h> #include<iostream> #include<string.h> int main() { int 阅读全文
posted @ 2019-12-31 19:22 西西嘛呦 阅读(805) 评论(0) 推荐(0)
摘要:函数指针:是指向函数的指针变量,因而函数指针本身应该是指针变量,只不过指针变量指向函数。 指针函数:带指针的函数,即本质是一个函数。 函数指针实例: #include<stdio.h> #include<iostream> int max(int, int); int min(int, int); 阅读全文
posted @ 2019-12-31 18:29 西西嘛呦 阅读(726) 评论(0) 推荐(0)
摘要:右键点击项目名,找到属性,找到c/c++,打开预处理,在预处理定义中加入:_CRT_SECURE_NO_WARNINGS 阅读全文
posted @ 2019-12-31 18:28 西西嘛呦 阅读(465) 评论(0) 推荐(0)
摘要:一个函数在编译时被分配给一个入口地址。这个函数的入口地址就被称为函数指针。 #include<stdio.h> #include<iostream> int max(int, int); int main() { int (*p)(int,int); int a, b, c; p = max; pr 阅读全文
posted @ 2019-12-30 21:24 西西嘛呦 阅读(461) 评论(0) 推荐(0)
摘要:C语言不支持在注释中嵌入注释,此时可以利用#if #endf,举个例子: #include<stdio.h> #include<iostream> #if(0) int main() { char* b; b = (char*)"hello"; printf("%c\n", b[2]); syste 阅读全文
posted @ 2019-12-30 20:51 西西嘛呦 阅读(1175) 评论(0) 推荐(0)
摘要:1.字符数组由若干个元素组成,每个元素中放一个字符,而字符指针变量中存放的是地址(字符串第一个字符的地址),而不是将字符串放到字符指针变量中。 2.赋值方式。对字符数组只能对各个元素进行赋值,不能用以下办法对字符数组进行赋值。 char str[20]; str = "ni hao a"; 而对于字 阅读全文
posted @ 2019-12-30 20:37 西西嘛呦 阅读(1155) 评论(0) 推荐(1)
摘要:第一种: #include<stdio.h> #include<iostream> void copy_string(char* p1, char* p2) { for (; *p1 != '\0'; *p1++,*p2++) { *p2 = *p1; } *p2 = '\0'; } int mai 阅读全文
posted @ 2019-12-30 20:18 西西嘛呦 阅读(3017) 评论(0) 推荐(0)
摘要:1.使用数组下标进行复制 #include<stdio.h> #include<iostream> void copy_string(char str1[], char str2[]) { int i = 0; while (str1[i] != '\0') { str2[i] = str1[i]; 阅读全文
posted @ 2019-12-30 20:05 西西嘛呦 阅读(6128) 评论(0) 推荐(1)