- 博客(83)
- 收藏
- 关注
原创 有C基础学习C++第九天(类和对象-对象特性)
1.构造函数和析构函数。2.构造函数的分类与调用。3.浅拷贝与深拷贝。4.静态成员变量。5.静态成员函数。6.成员变量和成员函数分开存储。7.this指针的用途。8.空指针访问成员函数。9.const修饰成员函数。
2022-12-21 13:47:57
167
原创 有C基础学习C++第八天(类和对象-封装)
1.创建类,属性,行为。2.3种访问权限,公共权限 public ,保护权限 protected,私有权限 private。3.class和struct 的区别。4.成员属性私有化。5.点和圆关系案例。
2022-12-18 20:54:25
172
原创 有C基础学习C++第六天(引用)
1.引用做函数参数(1.值传递,2.地址传递,3.引用传递)2.引用做函数返回值。3.引用的本质在C++内部中是一个指针常量。
2022-12-18 15:35:58
117
原创 有C基础学习C++第三天(指针)
1.定义指针2.使用指针3.指针占用内存空间都是4个字节4.const修饰指针 常量指针5.const修饰常量 指针常量6.const修饰指针和常量7.数组指针8.指针和函数:9.案例:封装一个函数,利用冒泡排序,实现对整数型数组的升序排列
2022-12-16 20:35:23
260
原创 有C基础学C++第二天(数组,函数)
1.一维数组,二维数组,查看占用内存空间,查看元素个数,查看地址。2.函数4种常见样式:1.无参无返,2.有参无返,3.无参有返,4.有参有返。3.函数声明:要想把函数写在main函数的后面,得提前对函数声明,告诉编译器函数的存在,函数的声明可以有多次,但定义只能有一次。
2022-12-16 14:22:38
95
原创 有C基础学习C++第一天(基础语法)
1.输入的代码与c不同,c:printf;2.科学计数法3.C风格字符串,用数组,不能用string4.c++的输入5.++x, x++6.continue语句, break语句7.goto语句
2022-12-15 19:22:33
218
原创 C语言第31天,动态内存分配(一),malloc,free,calloc,realloc函数初识
mallocfree#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<errno.h>#include<string.h>//malloc free//malloc函数向内存申请一块连续可用的空间,并返回指向这块空间的指针。//如果开辟失败,则返回一个NULL指针,因此malloc的返回值一定要做检查//返回值的类型是void*,所
2021-08-04 22:12:14
132
原创 C语言第30天,实现通讯录的增删改查
头文件 contact.h#define _CRT_SECURE_NO_WARNINGS#define MAX 1000#define MAX_NAME 20#define MAX_SEX 5#define MAX_TELE 12#define MAX_ADDR 30#include<stdio.h>#include<string.h>struct PeoInfo { char name[MAX_NAME]; int age; char sex[MAX_
2021-08-03 21:48:23
192
原创 C语言第29天,结构体位段,枚举,联合
结构体位段#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>//结构体位段struct S { int a : 2; int b : 5; int c : 10; int d : 30;};int main() { struct S s; printf("%d\n", sizeof(s));//8 return 0;}
2021-08-02 17:04:13
98
原创 C语言第28天,结构体进阶,嵌套初始化,内存对齐,传参
结构体全局变量,局部变量#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>struct Stu { char name[20]; char tele[12]; char sex[10]; int age;}s4, s5, s6;//s4,s5,s6 - 全局变量struct Stu s3;//全局变量int main() { struct Stu s1; struct Stu s2;//s1,s2 - 局部变量 re
2021-07-31 21:20:49
117
原创 C语言第28天,字符函数和内存函数的使用与剖析
字符函数#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <string.h>#include <ctype.h>//字符分类函数int main() { char ch = 'w'; int ret = islower(ch);//判断是否是小写字母 printf("%d\n", ret);//2 int ret2 = isdigit(ch);//判断是否是数字 printf(
2021-07-31 18:16:16
83
原创 C语言第28天,字符串使用与剖析(二),strstr,strtok,strerror
strstr - 查找子字符串#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <string.h>//strstr - 查找子字符串char* my_strstr(const char* p1, const char* p2) { char* s1 = NULL; char* s2 = NULL; char* cur = (char*)p1; if (*p2 == '\0') { retu
2021-07-31 13:39:55
100
原创 C语言第27天,字符串函数使用与剖析(一),strlen,strcpy,strcat,strcmp,strncpy,strncat,strcmp
strlen - 求字符串长度#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <string.h>//strlen - 求字符串长度//字符串以'\0'作为结束标志,strlen函数返回的是在字符串中'\0'前面出现的字符个数(不包含'\0')//参数指向的字符串必须要以'\0'结束//注意函数的返回值为size_t,是无符号的int my_strlen(char* str) { int co
2021-07-29 21:32:08
105
原创 杨氏矩阵查找数字
杨氏矩阵查找数字#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>//杨氏矩阵查找数字int FindNum(int arr[3][3], int k, int row, int col) { int x = 0; int y = col - 1; while (x <= row - 1 && y >= 0) { if (arr[x][y] > k) { y--; } else
2021-07-28 16:37:57
90
原创 C语言第26天,练习题,旋转字符串 || 判断一个字符串是否为另一个字符串旋转后得到的
旋转字符串#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <string.h>//旋转字符串//1.暴力求解法void left_move(char* arr, int k) { int i = 0; int len = strlen(arr); for (i = 0; i < k; i++) { //左旋转一个字符 char tmp = *arr; int j = 0;
2021-07-27 19:53:28
125
原创 C语言第25天,练习题,杨辉三角
unsigned#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>int main() { unsigned char a = 200;//无符整型 unsigned char b = 100; unsigned char c = 0; c = a + b;//整型提升 printf("%d %d", a + b, c);//300,44} #define _CRT_SECURE_NO_WARNINGS#include
2021-07-26 20:32:06
169
原创 C语言第25天,练习题,喝汽水 || 数组使奇数全部位于偶数的前面
结构体#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>struct S { int a; int b;};int main() { struct S a, * p = &a; a.a = 99; printf("%d\n", a.a);//99 printf("%d\n", p->a);//99 printf("%d\n", (*p).a);//99 //printf("%d\n", *p.a);//
2021-07-26 11:43:01
81
原创 C语言第24天,练习题,水仙花数 || 打印菱形
水仙花数#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <math.h>//水仙花数int main() { int i = 0; for (i = 0; i <= 100000; i++) { //判断i是否为水仙花数(自幂数) //1.计算i的位数 n位数 int n = 1; int tmp = i; int sum = 0; while (tmp /= 10)
2021-07-25 20:06:40
71
原创 C语言第24天,练习题,字符串逆序输出 || 求Sn=a+aa+aaa+aaaa+......的前n项之和
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>int main() { unsigned long pulArray[] = { 6,7,8,9,10 }; unsigned long* pulPtr; pulPtr = pulArray; //pulPtr - 元素6的地址 *(pulPtr + 3) += 3; //pulPtr+3 - 元素9的地址 printf("%d,%d\n", *pulPtr, *(pulPt
2021-07-25 18:52:06
97
原创 C语言第24天,指针难题
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>int main() { int a[5] = { 1,2,3,4,5 }; int* ptr = (int*)(&a + 1); printf("%d,%d\n", *(a + 1), *(ptr - 1));//2,5 //a是首元素地址,a+1是第二个元素的地址 //ptr-1是元素 5 的地址 return 0;}#define _CRT_SECURE_NO
2021-07-25 17:21:56
246
原创 C语言第23天,sizeof(),strlen()的运用示例(超详细)
整型数组,字符数组#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <string.h>int main() { //数组名是首元素的地址 //例外: //1.sizeof(数组名) - 数组名表示整个数组 //2.&数组名 - 数组名表示整个数组 //整型数组 - sizeof int a[] = { 1,2,3,4 };//4*4=16 printf("%d\n", sizeof
2021-07-24 17:33:58
158
原创 C语言第22天,指针(六)
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>int main() { int arr[10] = { 0 }; int(*p)[10] = &arr;//取出数组的指针 int(*pf)(int, int);//函数指针 int(*pfArr[4])(int, int);//pfArr是函数指针数组 int(*(*ppfArr)[4])(int, int) = &pfArr; //ppfArr是一个数组指
2021-07-22 16:45:54
55
原创 C语言第21天,指针(五),计算器(使用函数指针数组)
1.计算器 不使用函数指针数组#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>//计算器void menu() { printf("*********************\n"); printf("** 1.add 2.sub **\n"); printf("** 3.mul 4.div **\n"); printf("** 0.exit **\n");}int Add(int x
2021-07-21 19:13:15
109
原创 C语言第21天,指针(四),函数指针 | 函数指针数组
函数指针#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>//函数指针int Add(int x, int y) { int z = 0; z = x + y; return z;}void Print(char* str) { printf("%s\n", str);}int main() { int a = 10; int b = 20; int arr[10] = { 0 }; int(*p)[10]
2021-07-21 18:50:36
85
原创 C语言第21天,指针(三),传参
一维数组传参#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>//一维数组传参void test(int arr[]) { }//okvoid test(int arr[10]) { }//okvoid test(int* arr) { }//okvoid test2(int* arr[20]) { }//okvoid test2(int* arr) { }//okvoid test2(int** arr) {
2021-07-20 16:19:15
54
原创 C语言第20天,指针(二),数组指针
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>int main() { int* p1 = NULL;//p1是整型指针-指向整型的指针-可以存放整型的地址 char* pc = NULL;//pc是字符指针-指向字符的指针-可以存放字符的地址 //数组指针-指向数组的指针-存放数组的地址 //arr - 首元素地址 //&arr[0] - 首元素地址 //&arr - 数组的地址 int arr[10]
2021-07-19 19:21:35
59
原创 C语言第20天,指针(一)
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>int main() { char arr1[] = "abcde";//地址不同 char arr2[] = "abcde"; if (arr1 == arr2) { printf("yes/n"); } else { printf("no\n"); } printf("----------------------\n"); char* p1 = "abcde
2021-07-19 17:58:13
52
原创 C语言第19天,数据的存储(一)
原码,反码,补码#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>int main() { int a = 20;//4个字节-32bit //00000000000000000000000000010100 - 原码 //00000000000000000000000000010100 - 反码 //00000000000000000000000000010100 - 补码 //0x00000014 int b = -10;
2021-07-16 19:32:14
68
原创 C语言第19天,结构体
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>//描述一个学生//struct 机构体关键字 Stu-结构体标签 struct Stu-结构提类型typedef struct Stu { //成员变量 char name[20]; short age; char tele[12]; char sex[5];}Stu;void Print1(Stu tmp) { printf("name: %s\n", tmp.na
2021-07-16 15:38:17
61
原创 C语言第19天,递归练习题(五)
输入一个正整数,返回组成它的数字之和#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>//输入一个正整数,返回组成它的数字之和int DigitSum(unsigned int num) { if (num > 9) { return DigitSum(num / 10) + num % 10; } else { return num; }}int main() { unsigned int num =
2021-07-16 13:59:28
86
原创 C语言第18天,练习题(四)
用函数打印arr数组的内容,不使用数组下标,使用指针#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>//用函数打印arr数组的内容,不使用数组下标,使用指针void Print(int* p, int sz) { int i = 0; for (i = 0; i < sz; i++) { printf("%d ", *(p + i)); }}int main() { int arr[] = { 1,2,3,4
2021-07-15 17:56:25
83
原创 C语言第18天,二进制练习题(三)
写一个函数,求一个数的二进制(补码)表示中有几个1#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>int count_one(int n) { int count = 0; while (n) { if (n % 2 == 1) { count++; } n = n / 2; } return count;}int main() { int a = 0; scanf("%d", &a); /
2021-07-15 16:07:45
200
原创 C语言第17天,练习题(二)
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>int main() { int arr[] = { 1,2,3,4,5 }; short* p = (short*)arr;//short 两个字节 int i = 0; for (i = 0; i < 4; i++) { *(p + i) = 0;//四次初始化,,每次2个字节,4次8个字节--即前两个数字 } for (i = 0; i < 5; i++)
2021-07-14 16:17:03
163
原创 C语言第16天,数组练习题(一)
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include<string.h>int main() { char str[] = "hello world"; printf("%d %d\n", sizeof(str), strlen(str)); //12 11 ---sizeof包括\0 char axX[] = "abcdefg"; char axY[] = { 'a','b','c','d',
2021-07-13 20:22:41
78
原创 C语言第16天,初始指针
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>int main() { //指针类型决定了指针进行解引用的时候,能够访问空间的大小 //int*p; *p能够访问4个字节 //char*p; *p能够访问4个字节 //double*p; *p能够访问8个字节 int a = 0x11223344; int* pa = &a; char* pc = &a; double* pd = &a; pri
2021-07-13 18:21:27
83
原创 C语言第15天,操作符(二)
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>void test1(int arr[]) { printf("%d\n", sizeof(arr));}void test2(char ch[]) { printf("%d\n", sizeof(ch));}int main() { int arr[10] = { 0 }; char ch[10] = { 0 }; printf("%d\n", sizeof(arr));
2021-07-11 17:53:20
112
原创 C语言第15天,操作符(一)
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>//交换两个变量的值,不使用第三个变量int main() { //加减法-可能会溢出 int a = 3; int b = 5; a = a + b; b = a - b; a = a - b; printf("a=%d b=%d\n", a, b); printf("--------------\n"); //异或法 int a2 = 4; int b2 =
2021-07-11 15:50:07
46
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人