struct 结构体的用法简单介绍
来源:互联网 发布:鸟瞰图设计制作软件 编辑:程序博客网 时间:2024/05/15 06:42
1、先定义结构体类型,再定义结构体结构体变量
struct结构体类型名
{
//成员列表
};
//定义point结构体类型
struct point
{
int x;
int y;
};
//使用结构体类型定义两个变量
structpoint p1;
structpoint p2;
2、同时定义结构体类型和结构体变量
struct结构体名
{
//成员列表;
}结构体变量1,结构体变量2...;
struct point
{
int x;
int y;
}p1;
struct point p2;// 使用结构体类型定义1个变量
访问结构体变量的成员采用如下语法
结构体变量.成员名
初始化结构体变量
可以直接对结构体变量执行初始化
struct rect
{
int x;
int y;
int width;
int height;
} rect1 = {20,30,200,300};
--------------------------------
//下面的代码是错误的!!!!!
// rect1 = {20,30,200,300};
--------------------------------
// 还可以如下方法:
struct rect rect2 = {10,10,10,90};
//如果用typedef起一个新名称可以有如下用法
struct point
{
int x;
int y;
};
typedef struct point FKPoint;
FKPoint p1 = {20,30};
FKPoint p2 = {30,98};
--------------------------
//下面的代码是错误的
// p1 = {2,3};
--------------------------
//依次对结构体变量的每个成员变量赋值,这总是正确的
p1.x = 10;
p1.y = 20;
- struct 结构体的用法简单介绍
- 结构(struct)的用法
- 结构体(struct) 用法
- 关于struct msghdr结构体的介绍
- C中结构体struct的用法
- 结构体struct用法手札
- C#-Struct简单的用法
- Go语言,struct结构体的那些奇怪的用法
- swift的struct结构体类型介绍使用
- struct stat结构体的详解和用法
- struct stat结构体的详解和用法
- struct stat结构体的详解和用法 .
- struct stat结构体的详解和用法
- struct stat结构体的详解和用法
- struct stat结构体的详解和用法
- struct stat结构体的详解和用法
- struct stat结构体的详解和用法
- struct stat结构体的详解和用法
- Centos 7 - 静态IP设置
- 大龄程序员的未来在何方
- 【spring-security】/j_spring_security_logout 404
- myBatis资料(关于Mapper文件配置的,很全,有时间看看)
- Effective C++(条款13-17)
- struct 结构体的用法简单介绍
- MouTeam创始人:改变世界这种事就由我来做吧!
- SLB技术原理浅析
- http请求流程
- [leetcode] 225. Implement Stack using Queues 解题报告
- Web项目导出为war文件,热部署到tomcat运行
- angularjs的过滤器
- 用cxf集成spring的demo
- 图像检索公开数据集