- #include <stdio.h>
- int main()
- {
- //第一种定义及初始化赋值
- struct lv1
- {
- char *name;
- int age;
- };
- struct lv1 l1={"吕1",3};
- printf("l1.name=%s\tl1.age=%d\n",l1.name,l1.age);
- l1.name="栋6"; //改变l1的name的值
- l1.age=8; //改变l1的age的值
- printf("l1.name=%s\tl1.age=%d\n",l1.name,l1.age);
- //第二种定义及初始化赋值
- struct lv2
- {
- char *name;
- int age;
- } l2={"国2",4},l3={"栋3",5};
- printf("l2.name=%s\tl2.age=%d\nl3.name=%s\tl3.age=%d\n",l2.name,l2.age,l3.name,l3.age);
- //第三种定义及初始化赋值
- struct lv3
- {
- char *name;
- int age;
- } l4,l5;
- l4.name="国4";
- l4.age=6;
- l5.name="栋5";
- l5.age=7;
- printf("l4.name=%s\tl4.age=%d\nl5.name=%s\tl5.age=%d\n",l4.name,l4.age,l5.name,l5.age);
- char *p1={"abcdefg"};
- printf("第一次:p1=%s\n",p1);
- p1="hijklmn";
- printf("第二次:p1=%s\n",p1);
- return 0;
- }
复制代码
|
|