#include <stdio.h>
#include<string.h>
struct obj {
char *obj_name;
double price;
};
struct student {
int id;
int age;
char *name;
struct obj obj1;
} s = {1, 3, "aa"};
void modify(struct student *p) {
p->age = 100;
}
union Object {
int a;
char b;
float c;
};
int main() {
struct student stu = {1, 12, "小明"};
printf("%d %d %s\n", stu.id, stu.age, stu.name);
struct student stuu = {.name="hf"};
printf("%s", stuu.name);
stuu.age = 19;
printf("%d", stuu.age);
printf("%d\n", sizeof(int));
printf("%d\n", sizeof(double));
int arr[10];
printf("%d\n", sizeof(arr));
printf("%d\n", sizeof(arr[0]));
printf("%d\n", sizeof(struct student));
printf("%d\n", sizeof(struct obj));
struct student S[3] = {
{1, 24, "sdh", "pen", 5},
{23, 45, "wuli", "pencil", 432},
{4, 455, "lii", "lapstop", 234145}
};
printf("%\n", S[2].name);
struct student *p = &S;
printf("%s\n", (p + 2)->name);
printf("%s\n", (*(p + 2)).name);
struct student *pp = &stu;
modify(&stu);
printf("%d\n", pp->age);
printf("\n");
union Object object;
object.a = 129;
printf("%d\n", object.b);
union Object ob = {.c=23.7};
union Object *op = &ob;
printf("%.1f\n", op->c);
printf("%.1f\n", op->b);
}
测试结果:
D:\CodeCpp\untitled2\cmake-build-debug\untitled2.exe
1 12 小明
hf194
8
40
4
32
16
%
lii
lii
100
-127
23.7
0.0