惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
The Last Watchdog
The Last Watchdog
T
Tenable Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
Simon Willison's Weblog
Simon Willison's Weblog
V
Vulnerabilities – Threatpost
F
Fortinet All Blogs
Microsoft Security Blog
Microsoft Security Blog
A
Arctic Wolf
云风的 BLOG
云风的 BLOG
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
GbyAI
GbyAI
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
U
Unit 42
MyScale Blog
MyScale Blog
B
Blog
Spread Privacy
Spread Privacy
S
Schneier on Security
Project Zero
Project Zero
L
LINUX DO - 热门话题
M
MIT News - Artificial intelligence
F
Full Disclosure
WordPress大学
WordPress大学
Apple Machine Learning Research
Apple Machine Learning Research
Cyberwarzone
Cyberwarzone
AWS News Blog
AWS News Blog
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
Security Latest
Security Latest
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Tailwind CSS Blog
K
Kaspersky official blog
Recent Announcements
Recent Announcements
NISL@THU
NISL@THU
Cisco Talos Blog
Cisco Talos Blog
S
Securelist
P
Privacy & Cybersecurity Law Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
The Exploit Database - CXSecurity.com
V
Visual Studio Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Webroot Blog
Webroot Blog

博客园 - SPARON

[转] 在 Windows Server 2008 R2 下用 Visual Studio 2010 编译 Chrome 与 WebKit Chromium Port [转]JVM调优总结 6 个基于 HTML5 实现的多媒体播放器 35个五彩缤纷的网页设计作品欣赏 关于setInterval调用对象方法的问题 【收藏】27个jQuery表单插件分享 【收藏】开发人员看过来:11 个免费的开源 IDE Web开发人员应当知道的15个开源项目 终于还是走到了这步! 【转】27 款经典的CSS 框架 如果收购SUN的是Microsoft... CreateFileMapping和MapViewOfFile函数 XP安装 安全补丁KB905414 后本地连接丢失的解决方法 C、CPP const 详解 C语言运算符优先级 详细列表 C语言学习之#define用法 [转]JDK里的设计模式 记CPU的一次复频 C语言字符串转数值
typedef struct和struct定义结构体的区别
SPARON · 2010-12-06 · via 博客园 - SPARON

[知识点] 

结构也是一种数据类型, 可以使用结构变量, 因此, 像其它类型的变量一样, 在使用结构变量时要先对其定义。

定义结构变量的一般格式为: 

struct 结构名
{
      类型 变量名;
      类型 变量名;
      ...
} 结构变量;

结构名是结构的标识符不是变量名。

另一种常用格式为:

typedef struct 结构名
{
      类型 变量名;
      类型 变量名;
      ...
} 结构别名;
   

另外注意: 在C中,struct不能包含函数。在C++中,对struct进行了扩展,可以包含函数。

下面分三块来讲述:

1 首先:

在C中定义一个结构体类型要用typedef:

typedef struct Student
{
    
int a;
}Stu;

于是在声明变量的时候就可:Stu stu1;

如果没有typedef就必须用struct Student stu1;来声明

这里的Stu实际上就是struct Student的别名。

另外这里也可以不写Student(于是也不能struct Student stu1;了)

typedef struct
{
    
int a;
}Stu;

但在c++里很简单,直接

struct Student
{
    
int a;
};

于是就定义了结构体类型Student,声明变量时直接Student stu2;

===========================================

2其次:

在c++中如果用typedef的话,又会造成区别:

struct   Student   
{   
    
int   a;   
}stu1;
//stu1是一个变量 
  
typedef   
struct   Student2   
{   
    
int   a;   
}stu2;
//stu2是一个结构体类型   

使用时可以直接访问stu1.a

但是stu2则必须先   stu2 s2;

然后               s2.a=10;

===========================================

3 掌握上面两条就可以了,不过最后我们探讨个没多大关系的问题

如果在c程序中我们写:

typedef struct  
{
    
int num;
    
int age;
}aaa,bbb,ccc;

这算什么呢?

我个人观察编译器(VC6)的理解,这相当于

typedef struct  
{
    
int num;
    
int age;
}aaa;
typedef aaa bbb;
typedef aaa ccc;

也就是说aaa,bbb,ccc三者都是结构体类型。声明变量时用任何一个都可以,在c++中也是如此。但是要注意的是这个在c++中如果写掉了typedef关键字,那么aaa,bbb,ccc将是截然不同的三个对象。