C/C++ 结构体与指针笔记
结构体的定义与使用:
#include <stdio.h>
#include <stdlib.h>
struct Student
{
int num;
char name[30];
char age;
};
int main(int argc, char* argv[])
{
struct Student stu = { 1001, "lyshark", 22 };
printf("普通引用: %d --> %s \n", stu.num, stu.name);
struct Student *ptr; // 定义结构指针
ptr = &stu; // 指针的赋值
printf("指针引用: %d --> %s \n", ptr->num, ptr->name);
system("pause");
return 0;
}
动态分配结构体成员:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
struct Student
{
int num;
char name[30];
char age;
};
struct Student *stu = malloc(sizeof(struct Student));
stu->num = 1001;
stu->age = 24;
strcpy(stu->name, "lyshark");
printf("姓名: %s 年龄: %d \n", stu->name, stu->age);
// ----------------------------------------------------------
struct Person
{
char *name;
int age;
}person;
struct Person *ptr = &person;
ptr->name = (char *)malloc(sizeof(char)* 20);
strcpy(ptr->name, "lyshark");
ptr->age = 23;
printf("姓名: %s 年龄: %d \n", ptr->name, ptr->age);
free(ptr->name);
system("pause");
return 0;
}
结构体变量数组:
#include <stdio.h>
#include <stdlib.h>
typedef struct Person
{
int uid;
char name[64];
}Person;
void Print(struct Person *p,int len)
{
for (int x = 0; x < len; x++)
{
printf("%d \n", p[x].uid);
}
}
int main(int argc, char* argv[])
{
// 栈上分配结构体(聚合初始化)
struct Person p1[] = {
{ 1, "aaa" },
{ 2, "bbb" },
{ 3, "ccc" },
};
int len = sizeof(p1) / sizeof(struct Person);
Print(p1, len);
// 在堆上分配
struct Person *p2 = malloc(sizeof(struct Person) * 5);
for (int x = 0; x < 5; x++)
{
p2[x].uid = x;
strcpy(p2[x].name, "aaa");
}
Print(p2, 5);
system("pause");
return 0;
}
结构体深浅拷贝
#include <stdio.h>
#include <stdlib.h>
typedef struct Person
{
int uid;
char *name;
}Person;
int main(int argc, char* argv[])
{
struct Person p1,p2;
p1.name = malloc(sizeof(char)* 64);
strcpy(p1.name, "admin");
p1.uid = 1;
p2.name = malloc(sizeof(char)* 64);
strcpy(p2.name, "guest");
p2.uid = 2;
// p2 = p1; 浅拷贝
// 深拷贝
if (p1.name != NULL)
{
free(p1.name);
p1.name == NULL;
}
p1.name = malloc(strlen(p2.name) + 1);
strcpy(p2.name, p1.name);
p2.uid = p1.uid;
printf("p2 -> %s \n", p2.name);
system("pause");
return 0;
}
结构体字段排序: 首先对比结构中的UID,通过冒泡排序将UID从小到大排列,也可以通过Name字段进行排序.
#include <stdio.h>
#include <stdlib.h>
struct Student
{
int uid;
char name[32];
double score;
};
int StructSort(struct Student *stu,int len)
{
for (int x = 0; x < len - 1; x++)
{
for (int y = 0; y < len - x - 1; y++)
{
// if (strcmp(stu[y].name, stu[y + 1].name) > 0)
if (stu[y].uid > stu[y + 1].uid)
{
// 结构体变量互换,将用户UID从小到大排列
struct Student tmp = stu[y];
stu[y] = stu[y + 1];
stu[y+1] = tmp;
}
}
}
return 0;
}
void MyPrint(struct Student *stu,int len)
{
for (int x = 0; x < len; x++)
printf("Uid: %d Name: %s Score: %.1f \n", stu[x].uid,stu[x].name,stu[x].score);
}
int main(int argc, char* argv[])
{
struct Student stu[3] = {
{8,"admin",79.5},
{5,"guest",89.5},
{1,"root",99},
};
StructSort(stu, 3); // 调用排序
MyPrint(stu, 3); // 输出结果
system("pause");
return 0;
}
结构体数据之间的交换:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student
{
char *name;
int score[3];
};
int StructExchange(struct Student *stu, int len, char *str1,char *str2)
{
struct Student *ptr1;
struct Student *ptr2;
// 找到两个名字所对应的成绩
for (int x = 0; x < len; ++x)
{
if (!strcmp(stu[x].name, str1))
ptr1 = &stu[x];
if (!strcmp(stu[x].name, str2))
ptr2 = &stu[x];
}
// 开始交换两个人的成绩
for (int y = 0; y < 3; y++)
{
int tmp = ptr1->score[y];
ptr1->score[y] = ptr2->score[y];
ptr2->score[y] = tmp;
}
return 0;
}
void MyPrint(struct Student *stu,int len)
{
for (int x = 0; x < len; x++)
{
printf("Name: %s --> score: %d %d %d \n", stu[x].name, stu[x].score[0], stu[x].score[1], stu[x].score[2]);
}
}
int main(int argc, char* argv[])
{
struct Student stu[3];
// 动态开辟空间,并动态输入姓名与成绩
// admin 1 1 1 / guest 2 2 2 / root 3 3 3
for (int x = 0; x < 3; x++)
{
stu[x].name = (char *)malloc(sizeof(char) * 64); // 开辟空间
scanf("%s%d%d%d", stu[x].name, &stu[x].score[0], &stu[x].score[1], &stu[x].score[2]);
}
MyPrint(&stu, 3);
// 开始交换两个人名的成绩
StructExchange(&stu, 3, "root", "admin");
printf("----------------------------\n");
MyPrint(&stu, 3);
// 动态内存的释放
for (int y = 0; y < 3; y++)
free(stu[y].name);
system("pause");
return 0;
}
结构体偏移量计算:
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
int main(int argc, char* argv[])
{
struct Student
{
int uid;
char *name;
};
struct Student stu = { 1, "lyshark" };
int offset = (int *)( (char *)&stu + offsetof(struct Student, name) );
printf("指针首地址: %x \n", offset);
// =================================================================
// 第二种嵌套结构体取地址
struct SuperClass
{
int uid;
char *name;
struct stu
{
int sid;
char *s_name;
}stu;
};
struct SuperClass super = { 1001, "lyshark" ,1,"xiaowang"};
int offset1 = offsetof(struct SuperClass, stu);
int offset2 = offsetof(struct stu, sid);
// SuperClass + stu 找到 sid 首地址
int struct_offset = ((char *)&super + offset1) + offset2;
printf("sid首地址: %x --> %x \n", struct_offset, &super.stu.sid);
int stu_sid = *(int *) ((char *)&super + offset1) + offset2;
printf("sid里面的数值是: %d \n", stu_sid);
int stu_sid_struct = ((struct stu *)((char *)&super + offset1))->sid;
printf("sid里面的数值是: %d \n", stu_sid_struct);
system("pause");
return 0;
}
结构体嵌套一级指针
#include <stdio.h>
#include <stdlib.h>
typedef struct Person
{
int id;
char *name;
int age;
}Person;
// 分配内存空间,每一个二级指针中存放一个一级指针
struct Person ** allocateSpace()
{
// 分配3个一级指针,每一个指针指向一个结构首地址
struct Person **tmp = malloc(sizeof(struct Person *) * 3);
for (int x = 0; x < 3; x++)
{
tmp[x] = malloc(sizeof(struct Person)); // (真正的)分配一个存储空间
tmp[x]->name = malloc(sizeof(char) * 64); // 分配存储name的空间
sprintf(tmp[x]->name, "name_%d", x);
tmp[x]->id = x;
tmp[x]->age = x + 10;
}
return tmp;
}
// 循环输出数据
void MyPrint(struct Person **person)
{
for (int x = 0; x < 3; x++)
{
printf("Name: %s \n", person[x]->name);
}
}
// 释放内存空间,从后向前,从小到大释放
void freeSpace(struct Person **person)
{
if (person != NULL)
{
for (int x = 0; x < 3; x++)
{
if (person[x]->name != NULL)
{
printf("%s 内存被释放 \n",person[x]->name);
free(person[x]->name);
person[x]->name = NULL;
}
free(person[x]);
person[x] = NULL;
}
free(person);
person = NULL;
}
}
int main(int argc, char* argv[])
{
struct Person **person = NULL;
person = allocateSpace();
MyPrint(person);
freeSpace(person);
system("pause");
return 0;
}
结构体嵌套二级指针
#include <stdio.h>
#include <stdlib.h>
struct Student
{
char * name;
}Student;
struct Teacher
{
char *name;
char **student;
}Teacher;
void allocateSpace(struct Teacher ***ptr)
{
// 首先分配三个二级指针,分别指向三个老师的结构首地址
struct Teacher **teacher_ptr = malloc(sizeof(struct Teacher *) * 3);
for (int x = 0; x < 3; x++)
{
// 先来分配老师姓名存储字符串,然后赋初值
teacher_ptr[x] = malloc(sizeof(struct Teacher)); // 给teacher_ptr整体分配空间
teacher_ptr[x]->name = malloc(sizeof(char)* 64); // 给teacher_ptr里面的name分配空间
sprintf(teacher_ptr[x]->name, "teacher_%d", x); // 分配好空间之后,将数据拷贝到name里面
// -------------------------------------------------------------------------------------
// 接着分配该老师管理的学生数据,默认管理四个学生
teacher_ptr[x]->student = malloc(sizeof(char *) * 4); // 给teacher_ptr 里面的student分配空间
for (int y = 0; y < 4; y++)
{
teacher_ptr[x]->student[y] = malloc(sizeof(char) * 64);
sprintf(teacher_ptr[x]->student[y], "%s_stu_%d", teacher_ptr[x]->name, y);
}
}
// 最后将结果抛出去
*ptr = teacher_ptr;
}
// 输出老师和学生数据
void MyPrint(struct Teacher **ptr)
{
for (int x = 0; x < 3; x++)
{
printf("老师姓名: %s \n", ptr[x]->name);
for (int y = 0; y < 4; y++)
{
printf("--> 学生: %s \n", ptr[x]->student[y]);
}
}
}
// 最后释放内存
void freeSpace(struct Teacher **ptr)
{
for (int x = 0; x < 3; x++)
{
if (ptr[x]->name != NULL)
{
free(ptr[x]->name);
ptr[x]->name = NULL;
}
for (int y = 0; y < 4; y++)
{
if (ptr[x]->student[y] != NULL)
{
free(ptr[x]->student[y]);
ptr[x]->student[y] = NULL;
}
}
free(ptr[x]->student);
ptr[x]->student = NULL;
}
}
int main(int argc, char* argv[])
{
struct Teacher **teacher_ptr = NULL;
allocateSpace(&teacher_ptr);
MyPrint(teacher_ptr);
freeSpace(teacher_ptr);
system("pause");
return 0;
}
结构体内嵌共用体:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
struct Person
{
int uid; // 编号
char name[20]; // 姓名
char jobs; // 老师=t 或 学生 = s
union
{
char stu_class[32]; // 学生所在班级
char tea_class[32]; // 老师的所教课程
}category;
};
int main(int argc, char* argv[])
{
struct Person person[3];
for (int x = 0; x < 3; x++)
{
// 首先输入前三项,因为这三个数据是通用的,老师学生都存在的属性
printf("输入: ID 姓名 工作类型(s/t) \n");
scanf("%d %s %c", &person[x].uid, &person[x].name, &person[x].jobs);
if (person[x].jobs == 's') // 如果是学生,输入stu_class
scanf("%s", person[x].category.stu_class);
if (person[x].jobs == 't') // 如果是老师,输入tea_class
scanf("%s", person[x].category.tea_class);
}
printf("--------------------------------------------------------------\n");
for (int y = 0; y < 3; y++)
{
if (person[y].jobs == 's')
printf("老师: %s 职务: %s \n", person[y].name, person[y].category.tea_class);
if (person[y].jobs == 't')
printf("学生: %s 班级: %s \n", person[y].name, person[y].category.stu_class);
}
system("pause");
return 0;
}
结构体与链表
结构体基本定义:
#include <stdio.h>
typedef struct Person
{
int uid;
char name[64];
}Person;
int main(int argc, char* argv[])
{
// 在栈上分配空间
struct Person s1 = { 100, "admin" };
printf("%s \n", s1.name);
// 在堆上分配空间
struct Person *s2 = malloc(sizeof(struct Person));
strcpy(s2->name, "lyshark");
printf("%s \n", s2->name);
system("pause");
return 0;
}
结构体变量数组:
#include <stdio.h>
#include <stdlib.h>
typedef struct Person
{
int uid;
char name[64];
}Person;
void Print(struct Person *p,int len)
{
for (int x = 0; x < len; x++)
{
printf("%d \n", p[x].uid);
}
}
int main(int argc, char* argv[])
{
// 栈上分配结构体(聚合初始化)
struct Person p1[] = {
{ 1, "aaa" },
{ 2, "bbb" },
{ 3, "ccc" },
};
int len = sizeof(p1) / sizeof(struct Person);
Print(p1, len);
// 在堆上分配
struct Person *p2 = malloc(sizeof(struct Person) * 5);
for (int x = 0; x < 5; x++)
{
p2[x].uid = x;
strcpy(p2[x].name, "aaa");
}
Print(p2, 5);
system("pause");
return 0;
}
结构体深浅拷贝
#include <stdio.h>
#include <stdlib.h>
typedef struct Person
{
int uid;
char *name;
}Person;
int main(int argc, char* argv[])
{
struct Person p1,p2;
p1.name = malloc(sizeof(char)* 64);
strcpy(p1.name, "admin");
p1.uid = 1;
p2.name = malloc(sizeof(char)* 64);
strcpy(p2.name, "guest");
p2.uid = 2;
// p2 = p1; 浅拷贝
// 深拷贝
if (p1.name != NULL)
{
free(p1.name);
p1.name == NULL;
}
p1.name = malloc(strlen(p2.name) + 1);
strcpy(p2.name, p1.name);
p2.uid = p1.uid;
printf("p2 -> %s \n", p2.name);
system("pause");
return 0;
}
结构体嵌套一级指针
#include <stdio.h>
#include <stdlib.h>
typedef struct Person
{
int id;
char *name;
int age;
}Person;
// 分配内存空间,每一个二级指针中存放一个一级指针
struct Person ** allocateSpace()
{
// 分配3个一级指针,每一个指针指向一个结构首地址
struct Person **tmp = malloc(sizeof(struct Person *) * 3);
for (int x = 0; x < 3; x++)
{
tmp[x] = malloc(sizeof(struct Person)); // (真正的)分配一个存储空间
tmp[x]->name = malloc(sizeof(char) * 64); // 分配存储name的空间
sprintf(tmp[x]->name, "name_%d", x);
tmp[x]->id = x;
tmp[x]->age = x + 10;
}
return tmp;
}
// 循环输出数据
void MyPrint(struct Person **person)
{
for (int x = 0; x < 3; x++)
{
printf("Name: %s \n", person[x]->name);
}
}
// 释放内存空间,从后向前,从小到大释放
void freeSpace(struct Person **person)
{
if (person != NULL)
{
for (int x = 0; x < 3; x++)
{
if (person[x]->name != NULL)
{
printf("%s 内存被释放 \n",person[x]->name);
free(person[x]->name);
person[x]->name = NULL;
}
free(person[x]);
person[x] = NULL;
}
free(person);
person = NULL;
}
}
int main(int argc, char* argv[])
{
struct Person **person = NULL;
person = allocateSpace();
MyPrint(person);
freeSpace(person);
system("pause");
return 0;
}
结构体嵌套二级指针
#include <stdio.h>
#include <stdlib.h>
struct Student
{
char * name;
}Student;
struct Teacher
{
char *name;
char **student;
}Teacher;
void allocateSpace(struct Teacher ***ptr)
{
// 首先分配三个二级指针,分别指向三个老师的结构首地址
struct Teacher **teacher_ptr = malloc(sizeof(struct Teacher *) * 3);
for (int x = 0; x < 3; x++)
{
// 先来分配老师姓名存储字符串,然后赋初值
teacher_ptr[x] = malloc(sizeof(struct Teacher)); // 给teacher_ptr整体分配空间
teacher_ptr[x]->name = malloc(sizeof(char)* 64); // 给teacher_ptr里面的name分配空间
sprintf(teacher_ptr[x]->name, "teacher_%d", x); // 分配好空间之后,将数据拷贝到name里面
// -------------------------------------------------------------------------------------
// 接着分配该老师管理的学生数据,默认管理四个学生
teacher_ptr[x]->student = malloc(sizeof(char *) * 4); // 给teacher_ptr 里面的student分配空间
for (int y = 0; y < 4; y++)
{
teacher_ptr[x]->student[y] = malloc(sizeof(char) * 64);
sprintf(teacher_ptr[x]->student[y], "%s_stu_%d", teacher_ptr[x]->name, y);
}
}
// 最后将结果抛出去
*ptr = teacher_ptr;
}
// 输出老师和学生数据
void MyPrint(struct Teacher **ptr)
{
for (int x = 0; x < 3; x++)
{
printf("老师姓名: %s \n", ptr[x]->name);
for (int y = 0; y < 4; y++)
{
printf("--> 学生: %s \n", ptr[x]->student[y]);
}
}
}
// 最后释放内存
void freeSpace(struct Teacher **ptr)
{
for (int x = 0; x < 3; x++)
{
if (ptr[x]->name != NULL)
{
free(ptr[x]->name);
ptr[x]->name = NULL;
}
for (int y = 0; y < 4; y++)
{
if (ptr[x]->student[y] != NULL)
{
free(ptr[x]->student[y]);
ptr[x]->student[y] = NULL;
}
}
free(ptr[x]->student);
ptr[x]->student = NULL;
}
}
int main(int argc, char* argv[])
{
struct Teacher **teacher_ptr = NULL;
allocateSpace(&teacher_ptr);
MyPrint(teacher_ptr);
freeSpace(teacher_ptr);
system("pause");
return 0;
}
静态链表 理解一下
#include <stdio.h>
#include <stdlib.h>
// 定义链表节点类型
struct LinkNode
{
int data;
struct LinkNode *next;
};
int main(int argc, char* argv[])
{
struct LinkNode node1 = { 10, NULL };
struct LinkNode node2 = { 20, NULL };
struct LinkNode node3 = { 30, NULL };
struct LinkNode node4 = { 40, NULL };
node1.next = &node2;
node2.next = &node3;
node3.next = &node4;
node4.next = NULL;
// 遍历链表结构
struct LinkNode *ptr = &node1;
while (ptr != NULL)
{
printf("%d \n", ptr->data);
ptr = ptr->next;
}
system("pause");
return 0;
}
动态链表
#include <stdio.h>
#include <stdlib.h>
// 定义链表节点类型
struct LinkNode
{
int data;
struct LinkNode *next;
};
struct LinkNode *init_link()
{ // 创建一个头结点,头结点不需要添加任何数据
struct LinkNode *header = malloc(sizeof(struct LinkNode));
header->data = 0;
header->next = NULL;
struct LinkNode *p_end = header; // 创建一个尾指针
int val = -1;
while (1)
{
scanf("%d", &val); // 输入插入的数据
if (val == -1) // 如果输入-1说明输入结束了
break;
// 先创建新节点
struct LinkNode *newnode = malloc(sizeof(struct LinkNode));
newnode->data = val;
newnode->next = NULL;
// 将节点插入到链表中
p_end->next = newnode;
// 更新尾部指针指向
p_end = newnode;
}
return header;
}
// 遍历链表
int foreach_link(struct LinkNode *header)
{
if (NULL == header || header->next == NULL)
return 0;
while (header->next != NULL)
{
printf("%d \n", header->data);
header = header->next;
}
return 1;
}
// 在header节点中oldval插入数据
void insert_link(struct LinkNode *header,int oldval,int newval)
{
struct LinkNode *pPrev = header;
struct LinkNode *Current = pPrev->next;
if (NULL == header)
return;
while (Current != NULL)
{
if (Current->data == oldval)
break;
pPrev = Current;
Current = Current->next;
}
// 如果值不存在则默认插入到尾部
//if (Current == NULL)
// return;
// 创建新节点
struct LinkNode *newnode = malloc(sizeof(struct LinkNode));
newnode->data = newval;
newnode->next = NULL;
// 新节点插入到链表中
newnode->next = Current;
pPrev->next = newnode;
}
// 清空链表
void clear_link(struct LinkNode *header)
{
// 辅助指针
struct LinkNode *Current = header->next;
while (Current != NULL)
{
// 保存下一个节点地址
struct LinkNode *pNext = Current->next;
printf("清空数据: %d \n", Current->data);
free(Current);
Current = pNext;
}
header->next = NULL;
}
// 删除值为val的节点
int remove_link(struct LinkNode *header, int delValue)
{
if (NULL == header)
return;
// 设置两个指针,指向头结点和尾结点
struct LinkNode *pPrev = header;
struct LinkNode *Current = pPrev->next;
while (Current != NULL)
{
if (Current->data == delValue)
{
// 删除节点的过程
pPrev->next = Current->next;
free(Current);
Current = NULL;
}
}
// 移动两个辅助指针
pPrev = Current;
Current = Current->next;
}
// 销毁链表
void destroy_link(struct LinkNode *header)
{
if (NULL == header)
return;
struct LinkNode *Curent = header;
while (Curent != NULL)
{
// 先来保存一下下一个节点地址
struct LinkNode *pNext = Curent->next;
free(Curent);
// 指针向后移动
Curent = pNext;
}
}
// 反响排序
void reverse_link(struct LinkNode *header)
{
if (NULL == header)
return;
struct LinkNode *pPrev = NULL;
struct LinkNode *Current = header->next;
struct LinkNode * pNext = NULL;
while (Current != NULL)
{
pNext = Current->next;
Current->next = pPrev;
pPrev = Current;
Current = pNext;
}
header->next = pPrev;
}
int main(int argc, char* argv[])
{
struct LinkNode * header = init_link();
reverse_link(header);
foreach_link(header);
clear_link(header);
system("pause");
return 0;
}
C/C++ 结构体与指针笔记的更多相关文章
- 【学习笔记】【C语言】指向结构体的指针
1.指向结构体的指针的定义 struct Student *p; 2.利用指针访问结构体的成员 1> (*p).成员名称 2> p->成员名称 3.代码 #include < ...
- c语言中较常见的由内存分配引起的错误_内存越界_内存未初始化_内存太小_结构体隐含指针
1.指针没有指向一块合法的内存 定义了指针变量,但是没有为指针分配内存,即指针没有指向一块合法的内浅显的例子就不举了,这里举几个比较隐蔽的例子. 1.1结构体成员指针未初始化 struct stude ...
- C#将结构体和指针互转的方法
. 功能及位置 将数据从托管对象封送到非托管内存块,属于.NET Framework 类库 命名空间:System.Runtime.InteropServices 程序集:mscorlib(在 msc ...
- C语言结构体和指针
指针也可以指向一个结构体,定义的形式一般为: struct 结构体名 *变量名; 下面是一个定义结构体指针的实例: struct stu{ char *name; //姓名 int num; //学号 ...
- 37深入理解C指针之---结构体与指针
一.结构体与指针 1.结构体的高级初始化.结构体的销毁.结构体池的应用 2.特征: 1).为了避免含有指针成员的结构体指针的初始化复杂操作,将所有初始化动作使用函数封装: 2).封装函数主要实现内存的 ...
- 深入了解Windows句柄到底是什么(句柄是逻辑指针,或者是指向结构体的指针,图文并茂,非常清楚)good
总是有新入门的Windows程序员问我Windows的句柄到底是什么,我说你把它看做一种类似指针的标识就行了,但是显然这一答案不能让他们满意,然后我说去问问度娘吧,他们说不行网上的说法太多还难以理解. ...
- 01.C语言关于结构体的学习笔记
我对于学习的C语言的结构体做一个小的学习总结,总结如下: 结构体:structure 结构体是一种用户自己建立的数据类型,由不同类型数据组成的组合型的数据结构.在其他高级语言中称为记录(record) ...
- 关于C语言结构体,指针,声明的详细讲解。——Arvin
关于结构体的详细分析 只定义结构体 struct Student { int age; char* name; char sex;//结构体成员 };//(不要忘记分号) Student是结构体的名字 ...
- c语言结构体&常指针和常量指针的区别
结构体: 关系密切但数据类型不尽相同, 常指针和常量指针的区别: char * const cp : 定义一个指向字符的指针常数,即const指针,常指针. const char* p : 定义一个指 ...
- C#调用c++Dll 结构体数组指针的问题
参考文章http://blog.csdn.net/jadeflute/article/details/5684687 但是这里面第一个方案我没有测试成功,第二个方案我感觉有点复杂. 然后自己写啦一个: ...
随机推荐
- Docker--简介&&安装
Docker 是一种应用容器引擎 一 容器 Linux系统提供了Namespace和Cgroup技术实现环境隔离和资源控制 其中Namespace是Linux提供的一种内核级别环境隔离的方法,能使一个 ...
- Java字节码与反射机制
字节码(Byte Code)是Java语言跨平台特性的重要保障,也是反射机制的重要基础.通过反射机制,我们不仅能看到一个类的属性和方法,还能在一个类里调用另外一个类的方法,但前提是我们得有相关类的字节 ...
- Java面试——数据库知识点
MySQL 1.建 主键:数据库表中对储存数据对象予以唯一和完整标识的数据列或属性的组合.一个数据列只能有一个主键,且主键的取值不能缺失,即不能为空值(Null). 超键:在关系中能唯一标识元组的属性 ...
- 每天学五分钟 Liunx 1000 | 软件篇:源码安装
软件安装流程 前面软件篇提到了通过 RPM 和 YUM 在线安装的机制安装软件,除了这两种方式之外还有一种通过源码来安装软件的方式.
- 【Altium Designer】五颜六色标识的PCB布板(增强PCB可视化特性)
出现上图中五颜六色的网络标识,对比各个网络会更加清晰,实现步骤如下 打开或关闭 View--->Net Color Override Active 快捷键 F5 设置 displa ...
- 2023第十四届极客大挑战 — PWN WP
WP可能有点简陋,因为是直接从docx导入到博客的,实在不想再重新写了!大家凑合着看吧!哈哈哈,问题不大! pwn方向出自:队友 nc_pwntools 只要过了chal1和chal2即可执行任意命令 ...
- 如何让pc端网站在手机上可以等比缩放的整个显示
将 头部标签的 <meta name="viewport" content="width=device-width, initial-scale=1.0&qu ...
- [转帖]oracle 审计日志清理
https://www.cnblogs.com/bangchen/p/7268086.html --进入审计日志目录: cd $ORACLE_BASE/admin/$ORACLE_SID/adum ...
- [转帖]Jmeter之界面语言设置
https://developer.aliyun.com/article/1173114#:~:text=%E6%B0%B8%E4%B9%85%E6%80%A7%E8%AE%BE%E7%BD%AE%E ...
- [转帖]linux 内核协议栈 TCP time_wait 原理、配置、副作用
https://my.oschina.net/u/4087916/blog/3051356 0. 手把手教你做中间件.高性能服务器.分布式存储技术交流群 手把手教你做中间件.高性能服务器.分布式存 ...