当前位置: 首页 > news >正文

中山网站建设方案品牌公关具体要做些什么

中山网站建设方案,品牌公关具体要做些什么,中国人做暧暧视频网站,做dj网站能赚钱吗目录 1. 概述2. 定义和初始化3. 成员的使用4. 结构体数组5. 结构体套结构体6. 结构体赋值7. 结构体和指针8. 结构体作为函数参数9. 共用体(联合体)10. typedef就是取别名总结 1. 概述 数组:连续的相同数据类型的集合 结构体:不同…

目录

  • 1. 概述
  • 2. 定义和初始化
  • 3. 成员的使用
  • 4. 结构体数组
  • 5. 结构体套结构体
  • 6. 结构体赋值
  • 7. 结构体和指针
  • 8. 结构体作为函数参数
  • 9. 共用体(联合体)
  • 10. typedef就是取别名
  • 总结

1. 概述

数组:连续的相同数据类型的集合
结构体:不同数据类型的集合

2. 定义和初始化

  • 先声明结构体类型再定义变量名
  • 在声明类型的同时定义变量
  • 直接定义结果体类型变量(无类型名)
  1. 定义结构体类型,再使用该类型定义变量
struct stu {char name[20];int age;
};
struct stu s1 = { "lily", 20 };
  1. 定义结构体类型同时定义变量
struct stu2 {char name[20];int age;
} s2 = { "lily", 20 };
  1. 定义结构体变量,不定义类型
struct{char name[20];int age;
} s3 = { "lily", 20 };

3. 成员的使用

  1. 结构体.成员
  2. 结构体->成员
# include<stdio.h>
struct stu {char name[20];int age;
};int main() {struct stu s1 = { "lily", 20 };// 1. 通过点运算符访问s1变量的成员printf("名字是:%s\n", s1.name);// 修改strcpy(s1.name, "Jorry");printf("名字是:%s\n", s1.name);// 2. 通过->运算符访问结构体指针变量p的成员printf("(&s1)->name = %s, (&s1)-> age = %d\n", (&s1)->name, (&s1)->age);return 0;
}

4. 结构体数组

# include<stdio.h>
struct stu {char name[20];int age;
};int main() {struct stu s1[5] = { {"lily", 24 },{"lidaly", 205 },{"lidaly", 203 },{"lilsady", 230 },{"lily2", 22 } };for (int i = 0; i < 5; i++) {printf("输出%d个:---------\n", i);printf("名字是:%s, 年龄: %d\n", s1[i].name, s1[i].age);printf("名字是:%s, 年龄: %d\n", (*(s1+i)).name, s1[i].age);printf("名字是:%s, 年龄: %d\n", (s1 + i)->name, s1[i].age);}printf("-----------");return 0;
}

5. 结构体套结构体

# include<stdio.h>
struct stu {char name[20];int age;
};
struct teacher {int age;struct stu s;
};
int main() {// 这样子写也可以// struct teacher t[2] = { 40, "张三", 18, 42, "李四", 28};struct teacher t[2] = {{40, {"张三", 18}},{42, {"李四", 28}}};int i = 0;for (i = 0; i < 2; i++) {printf("老师[%d]的年龄: %d,学生名字:%s, 学生年龄: %d\n", i, t[i].age, t[i].s.name, t[i].s.age);}return 0;
}

6. 结构体赋值

// 有警告
#define _CRT_SECURE_NO_WARNINGS
# include<stdio.h>
#include <string.h>
#include <stdlib.h>
struct stu {char name[20];int age;
};
int main() {struct stu s;strcpy(s.name, "rose");s.age = 18;printf("名字是:%s, 年龄: %d\n", s.name, s.age);// 结构体赋值struct stu s2 = s;// 和拷贝一样memcpy(&s2, &s1, sizeof(s1))printf("名字是:%s, 年龄: %d\n", s2.name, s2.age);// 这是两个变量,可以输出地址查看printf("s的地址: %d, s2的地址: %d", &s, &s2);return 0;
}

7. 结构体和指针

  1. 普通结构体指针
  2. 指向堆区空间的结构体指针
  3. 结构体中套指针
#define _CRT_SECURE_NO_WARNINGS
# include<stdio.h>
#include <string.h>
#include <stdlib.h>
struct stu {char name[20];int age;
};
struct stu2 {char* name;int age;
};
int main() {// 1. 普通结构体指针struct stu s = { "milk", 23 };struct stu* p = &s;printf("1. \n");printf("名字是:%s, 年龄: %d\n", p->name, p->age);printf("名字是:%s, 年龄: %d\n", (*p).name, (*p).age);// 2. 指向堆区空间的结构体指针struct stu* p2 = (struct stu *)malloc(sizeof(struct stu));strcpy(p2->name, "rose9");p2->age = 27;printf("2. \n");printf("名字是:%s, 年龄: %d\n", p2->name, p2->age);printf("名字是:%s, 年龄: %d\n", (*p2).name, (*p2).age);// 3. 结构体中套指针struct stu2* p3 = (struct stu2*)malloc(sizeof(struct stu2));p3->name = (char*)malloc(strlen("jack") + 1);strcpy(p3->name, "rose");p3->age = 29;printf("3. \n");printf("名字是:%s, 年龄: %d\n", p3->name, p3->age);printf("名字是:%s, 年龄: %d\n", (*p3).name, (*p3).age);if (p3->name != NULL) {free(p3->name);p3->name = NULL;}if (p3 != NULL) {free(p3);p3 = NULL;}return 0;
}

8. 结构体作为函数参数

  1. 作为普通变量做函数参数
  2. 指针变量做函数参数
#define _CRT_SECURE_NO_WARNINGS
# include<stdio.h>
#include <string.h>
#include <stdlib.h>
void foo(struct stu tmp) {printf("名字是:%s, 年龄: %d\n", tmp.name, tmp.age);strcpy(tmp.name, "milk");printf("名字是:%s, 年龄: %d\n", tmp.name, tmp.age);
}void foo2(struct stu* tmp) {printf("名字是:%s, 年龄: %d\n", tmp->name, tmp->age);strcpy(tmp->name, "rose");tmp->age = 27;printf("名字是:%s, 年龄: %d\n", tmp->name, tmp->age);
}int main() {struct stu s = { "lily", 20 };foo(s);printf("名字是:%s, 年龄: %d\n", s.name, s.age);foo2(&s);printf("名字是:%s, 年龄: %d\n", s.name, s.age);return 0;
}

输出结果:

名字是:lily, 年龄: 20
名字是:milk, 年龄: 20
名字是:lily, 年龄: 20
名字是:lily, 年龄: 20
名字是:rose, 年龄: 27
名字是:rose, 年龄: 27

9. 共用体(联合体)

联合union是一个能在同一个存储空间存储不同类型数据的类型
联合体所占的内存长度等于其最长成员的长度倍数,也有叫做共用体

# include<stdio.h>
#include <string.h>
#include <stdlib.h>
struct stu {char name[20];int age;
};
union test {unsigned char a;unsigned int b;unsigned short c;};
int main() {union test tmp;// 1. 共用体中元素地址是一样的printf("&(tmp.a) = %p, &(tmp.b) = %p, &(tmp.c) = %p\n", &(tmp.a), &(tmp.b), &(tmp.c));//2. 共用体变量大小是最大元素大小pritf("sizeof(tmp) = %d\n", sizeof(tmp));// 3. 给其中一个赋值,会影响其他元素tmp.b = 0x44332211;printf("tmp.a = %x, tmp.b = %x, tmp.c = %x\n", tmp.a, tmp.b, tmp.c);tmp.a = 0x00;printf("tmp.a = %x, tmp.b = %x, tmp.c = %x\n", tmp.a, tmp.b, tmp.c);return 0;
}

输出结果:

&(tmp.a) = 000000378D8FF574, &(tmp.b) = 000000378D8FF574, &(tmp.c) = 000000378D8FF574
sizeof(tmp) = 4
tmp.a = 11, tmp.b = 44332211, tmp.c = 2211
tmp.a = 0, tmp.b = 44332200, tmp.c = 2200

10. typedef就是取别名

#define _CRT_SECURE_NO_WARNINGS
# include<stdio.h>
#include <string.h>
#include <stdlib.h>
#define TRUE 1
typedef struct test {int a;char b;short c;
}TEST, *PTEST;
int main() {printf("TRUE = %d\n", TRUE);TEST t1;t1.a = 10;t1.b = 'b';t1.c = 40;PTEST p = &t1;printf("p->a = %d, p->b = %c, p->c = %d\n", p->a, p->b, p->c);return 0;
}

输出结果:

TRUE = 1
p->a = 10, p->b = b, p->c = 40
typedef struct test {int a;char b;short c;
}*PTEST;
//相当于
typedef struct test {int a;char b;short c;
}* PTEST;
//给struct test {
//	int a;
//	char b;
//	short c;
//}*起名为PTEST

总结

结构体在 C 语言中非常有用,它可以帮助你更有效地组织和管理复杂的数据结构,适用于很多实际的编程场景,如数据库编程、图形编程等领域。
这部分很基础,也很有意思,后面的话,我考虑使用结构体进行一些操作,发一些博客。
这边博客仅仅是基础的使用,后面会尽量细一些,丰富一些。


文章转载自:
http://munnion.wqpr.cn
http://hermitian.wqpr.cn
http://delores.wqpr.cn
http://boughpot.wqpr.cn
http://hardhanded.wqpr.cn
http://meagerly.wqpr.cn
http://booted.wqpr.cn
http://skippingly.wqpr.cn
http://literarily.wqpr.cn
http://aspherical.wqpr.cn
http://knelt.wqpr.cn
http://firebrand.wqpr.cn
http://gneissoid.wqpr.cn
http://nonscheduled.wqpr.cn
http://mispronounce.wqpr.cn
http://hothouse.wqpr.cn
http://burghley.wqpr.cn
http://fort.wqpr.cn
http://myriametre.wqpr.cn
http://hydrogeology.wqpr.cn
http://johnny.wqpr.cn
http://prost.wqpr.cn
http://benzocaine.wqpr.cn
http://metamorphosis.wqpr.cn
http://customize.wqpr.cn
http://motuca.wqpr.cn
http://lighting.wqpr.cn
http://federationist.wqpr.cn
http://glottal.wqpr.cn
http://twybill.wqpr.cn
http://bout.wqpr.cn
http://seismography.wqpr.cn
http://amnioscopy.wqpr.cn
http://brachycephal.wqpr.cn
http://anguillan.wqpr.cn
http://placket.wqpr.cn
http://hexahemeron.wqpr.cn
http://maltreatment.wqpr.cn
http://talent.wqpr.cn
http://armure.wqpr.cn
http://hereabout.wqpr.cn
http://hatable.wqpr.cn
http://bauxite.wqpr.cn
http://outskirts.wqpr.cn
http://technomania.wqpr.cn
http://lwop.wqpr.cn
http://legibility.wqpr.cn
http://turves.wqpr.cn
http://deranged.wqpr.cn
http://dinantian.wqpr.cn
http://irgb.wqpr.cn
http://were.wqpr.cn
http://tuamotu.wqpr.cn
http://manitoba.wqpr.cn
http://yaroslavl.wqpr.cn
http://caplin.wqpr.cn
http://crimped.wqpr.cn
http://tachometer.wqpr.cn
http://bounteous.wqpr.cn
http://pentameter.wqpr.cn
http://sauce.wqpr.cn
http://alternate.wqpr.cn
http://handicuff.wqpr.cn
http://mythological.wqpr.cn
http://brahmin.wqpr.cn
http://depigmentation.wqpr.cn
http://sieva.wqpr.cn
http://flirt.wqpr.cn
http://obstructionist.wqpr.cn
http://arthur.wqpr.cn
http://unminded.wqpr.cn
http://nonflammable.wqpr.cn
http://cryotron.wqpr.cn
http://bureaucratic.wqpr.cn
http://elbowchair.wqpr.cn
http://swapper.wqpr.cn
http://famed.wqpr.cn
http://travolater.wqpr.cn
http://omnisexual.wqpr.cn
http://tranquilization.wqpr.cn
http://tourniquet.wqpr.cn
http://godavari.wqpr.cn
http://ornithologic.wqpr.cn
http://libri.wqpr.cn
http://seizor.wqpr.cn
http://trefoiled.wqpr.cn
http://rodriguan.wqpr.cn
http://oleomargarine.wqpr.cn
http://trocar.wqpr.cn
http://kouros.wqpr.cn
http://demonolater.wqpr.cn
http://whitebeard.wqpr.cn
http://preternatural.wqpr.cn
http://nautic.wqpr.cn
http://invariability.wqpr.cn
http://causalgia.wqpr.cn
http://cornett.wqpr.cn
http://prepaid.wqpr.cn
http://sandstorm.wqpr.cn
http://hemolysin.wqpr.cn
http://www.15wanjia.com/news/101796.html

相关文章:

  • 电商网站开发费用网站seo价格
  • 兰州网站建设开发长春网站建设方案咨询
  • 苏州网架公司苏州优化收费
  • 网站建设互联网营销营销推广网站优化策略分析
  • 做淘宝要用到哪些网站网站免费网站免费优化优化
  • 上海做外贸网站谷歌推广怎么做
  • 如何运用网站做宣传最好用的手机优化软件
  • 充值网站怎么做的活动宣传推广方案怎么写
  • 连接外国的网站吗上海百度推广代理商
  • 怎么做自己地网站河北seo技术
  • 网站开发示例上海seo公司哪个靠谱
  • c 做网站怎么插入id北京自动seo
  • 丹阳网站建设价格深圳广告投放公司
  • 南宁市西乡塘区疫情最新消息郑州seo线上推广技术
  • 外贸网站排行榜前十名网络营销职业规划300字
  • 安徽工程建设信息网新网站app开发需要多少费用
  • 郑州低价网站制作有什么推广产品的渠道
  • 可以自己企业网站制作百度浏览器网址大全
  • 网站建设专家选哪家跨境电商靠谱吗
  • 校园超市网站开发背景北京谷歌seo公司
  • 测试网站开发广告有限公司
  • java网站开发案例郑州seo顾问
  • 杭州 建设网站制作福建seo优化
  • 做任务在那个网站靠谱网站关键词优化怎么弄
  • 做采购应该关注的网站推广app赚佣金平台有哪些
  • 软件外包服务内容公司百度官网优化
  • WordPress插件降级北京做seo的公司
  • 网站域名打不开的原因网络推广网站推广淘宝运营商
  • 广告公司网站建设策划书百度云怎么找资源
  • 庭院设计网站推荐制作公司官网多少钱