1. 如何解决文件冲突:
error : Pulling is not possible because you have unmerged files.
add : git add .
commit : git commit -m‘填写备注'
push : git pull <远程主机名> <远程分支名>:<本地分支名>
2. 如何给array分配内存:
In C, arrays are represented as a pointer to the first element. 将array定义为指针类型,分配内存。输出some_array的值,结果是array的first element的address.
int8_t x = 5;
int* some_array = malloc(sizeof(int8_t));
3. 如何给结构体分配内存
定义结构体struct Student
struct Student {
int id;
char* name;
};
定义student1:
struct Student student1;
student1.id = 5;
printf("Student 1's ID: %d\n", student1.id); //输出结果是5
定义student指针并分配内存:
struct Student *student2_ptr = malloc(sizeof(struct Student));
注:获取结构体成员有两种方式:
第一种:(*pointer).memberName
第二种:pointer->memberName
(*student2_ptr).id = 6;
或student2_ptr->id=6;
printf("Student 2's ID: %d\n", student2_ptr->id); //输出结果是6
不同的变量定义方式:
struct Student{
...
}s1,s2;
int main(){
struct Student s3;
}
4. typedef结构体
使用typedef可以自定义类型说明符,也就是自行为原有的数据类型取别名,但并没有生成新的数据类型。
typedef struct {
int id;
char* name;
} Student;
则自定义的数据类型叫Student
分配内存时:Student* student_ptr = malloc(sizeof(Student));
【对比struct结构体:struct Student *student2_ptr = malloc(sizeof(struct Student));】