数据结构-->结构体
来源:互联网 发布:tensorflow教程pdf 编辑:程序博客网 时间:2024/06/16 11:48
- 使用struct可以聚合不同数聚类性的数据,结构表示的是数据项的集合,每条数据项由其类型和名称指定;
struct { char name[10]; int age; float salary;}person;
- 对于数据成员的赋值可以以采用
.
来为数据成员进行赋值,需要注意的是对于字符性赋值需要使用strcpy
函数
来进行; - 还可以使用
typedef
来重新声明一个新的类型,使用上面的方式构造的只是一个变量,使用typedef
得到的是一个
新的类型,新的类型声明之后,可以使用类型来定义变量,但是对于person
就不可以用于定义变量;
#include<stdio.h>#include<stdlib.h>#include<string.h>#define true 1#define false 0struct { char name[10]; int age; float salary;}person;//同样的对于结构体来说,也是可以包含结构体的;typedef struct { int month; int day; int year;}date;typedef struct{ char name[10]; int age; float salary; date dob;}HumanBeing;bool Compare_struct(HumanBeing person1,HumanBeing person2){ if(strcmp(person1.name,person2.name)&&person1.age== person2.age&&person1.salary==person2.salary) return true; else return false;}int main(){ strcpy(person.name,"Hello world"); person.age=10; person.salary=12.255; printf("name: %s\n",person.name); printf("age: %d\n",person.age); printf("salary: %f\n",person.salary); HumanBeing myinfo; strcpy(myinfo.name,"new name"); myinfo.age=10; myinfo.salary=10.001; myinfo.dob.year=2015; myinfo.dob.month=11; myinfo.dob.day=23; HumanBeing person2; //对于相同类型的结构体是可以进行赋值的,但是不可以进行比较操作; myinfo=person2;}
阅读全文
0 0
- 数据结构-结构体
- 数据结构-->结构体
- 基本数据结构之一:结构体
- 数据结构-结构体的声明
- 数据结构 - 指针,数组,结构体
- 数据结构基础知识之结构体
- <复习>数据结构中的结构体
- 结构体和数据结构学习
- 数据结构-栈--结构体实现
- 数据结构-结构体的声明
- 数据结构学习记录-结构体
- 数据结构 - 结构
- 结构体数据结构的位成员
- 数据结构学习(结构体复习)
- 04-数据结构_预备知识-结构体
- ural1100--Final Standings--数据结构--结构体排序
- 数据结构(结构体定义,typedef)
- Nginx基本数据结构之ngx_http_request_t结构体
- html-5
- 2017秋招C++面经
- 第六周LeetCode算法题两道
- jQuery 取值、赋值的基本方法整理
- JavaScript之使用JavaScript模仿oop编程
- 数据结构-->结构体
- sed命令详解
- hdu 2157
- js关闭一个窗口并打开另一个窗口
- 树
- the new beginning
- java并发基础(五)--- 线程池的配置与定制ThreadPoolExecutor
- PTA 7-2 列车调度(25 分) 思路+超时代码+正确代码
- 对象的作用域