int main()
{
int num = 233;
int* pn = #
*pn = 233333;
pn = NULL;
printf("%d %p\n", num, pn);
int* const p1 = #
*p1 = 66;
int x = 6;
}
int main()
{
int age = 18;
int* pa = &age;
printf("%p %p %p\n", pa, &pa,&age);
int** pp = &pa;
printf("%p, %p %d", pp, *pp, **pp);
return 0;
}
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct {
int number;
char name[25];
int chinese;
int math;
int english;
} Student;
int cmp(const void *p1,const void *p2)
{
Student** s1 = p1;
Student** s2 = p2;
int total1 = (*s1)->chinese + (*s2)->english + (*s2)->math;
int total2 = (*s1)->chinese + (*s2)->english + (*s2)->math;
if (total1 != total2)
{
return total2 - total1;
}
if ((*s1)->chinese != (*s2)->chinese)
{
return(*s2)->chinese - (*s1)->chinese;
}
if ((*s1)->math != (*s2)->math)
{
return(*s2)->math - (*s1)->math;
}
if ((*s1)->english != (*s2)->english)
{
return(*s2)->english - (*s1)->english;
}
return strcmp((*s1)->name, (*s2)->name);
}
void print_stu_info(Student* p)
{
printf("%d %s %d %d %d\n",
p->number,
p->name,
p->chinese,
p->math,
p->english);
}
int main()
{
Student students[3];
for (int i = 0; i < 3; i++)
{
scanf("%d%s %d%d%d",
&students[i].number,
students[i].name,
&students[i].chinese,
&students[i].english,
&students[i].math);
}
Student* pstus[] = { students,students + 1,students + 2};
printf("排序前:\n");
for (int i = 0; i < 3; i++)
{
print_stu_info(pstus[i]);
}
qsort(pstus, 3, sizeof(pstus[0]), cmp);
printf("排序后:\n");
for (int i = 0; i < 3; i++)
{
print_stu_info(pstus[i]);
}
}