#include<stdio.h>
#include<stdlib.h>
int main() {
auto p = (char*)malloc(8);
for (int i = 0; i < 8; i++) {
p[i] = i + 1;
}
free(p);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct Car {
char maker[32];
int price;
};
struct Citizen {
char name[32];
int deposite;
Car* car;
};
void buy(Citizen* owner) {
Car* car = (Car*)malloc(sizeof(Car));
strcpy(car->maker, "Chevrolet");
car->price = 10;
owner->car = car;
owner->deposite -= car->price;
}
void discard(Citizen* who) {
free(who->car);
who->car = NULL;
}
void sell(Citizen* owner, Citizen* other) {
Car* car = owner->car;
car->price *= 0.5;
other->car = car;
owner->deposite += car->price;
other->deposite -= car->price;
owner->car = NULL;
}
int main()
{
Citizen shaofa = { "shaofa" ,100,NULL};
buy(&shaofa);
discard(&shaofa);
Citizen anybody = { "xxxx",1000,NULL };
sell(&shaofa,&anybody);
return 0;
}