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

推荐订阅源

雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - Franky
MyScale Blog
MyScale Blog
A
About on SuperTechFans
博客园_首页
B
Blog RSS Feed
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Vercel News
Vercel News
C
Check Point Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 【当耐特】
M
MIT News - Artificial intelligence
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
I
InfoQ
罗磊的独立博客

博客园 - 萧佰刚

Mtk Ft6306 touch 驱动 . 深圳市鑫侑触控技术有限公司 电容式触摸屏|电容式触摸屏厂|手机触摸屏厂|偏光片贴合 Qt Creator 常用快捷键 结构体指针的指针使用(转) System V共享内存资料 "互斥锁用于上锁,条件变量则用于等待" Linux下UDP编程 Linux Socket编程学习 linux管道学习资料 linux进程间通信——消息队列 C实现单链表(转) c语言 位操作 C语言枚举类型使用简介 字符数组 字符指针 sizeof strlen 的区别 Linux进程间共享临界区“信号量”编程 Linux下Socket编程 Linux下常用函数- 信号处理函数(转) linux信号signal常用信号 Linux 守护进程的编程方法(转)
指向结构体指针的例子
萧佰刚 · 2011-05-26 · via 博客园 - 萧佰刚

#include<stdio.h>
#define LEN 20
struct names
{
  
char first[LEN];
  
char last[LEN];
};struct guy
{
  
struct names handle;
  
char favfood[LEN];
  
char job[LEN];
  
float income;
};int main(void)
{
     
struct guy fellow[2]=
     {
        {{"Ewen","Villard"},"grilled salmon","personality coach",58112.00},
        {{"Rodney","Swillbelly"},"tripe""tabbid editor",232400.00}
    };
     
    
struct guy *him;    printf("address #1: %p  #2: %p\n",&fellow[0],&fellow[1]);
    
    him=&fellow[0];    printf("pointer #1: %p #2: %p\n",him,him+1);    printf("him->income is $%.2f  (*him)income is $%.2f\n",him->income,(*him).income);    him++;    printf("him->favfood is %s  him->handle.last is %s\n",him->favfood,him->handle.last);return 0;
}

输出结果

address #1:0x0012fea4 #2:0x0012fef8pointer #1:0x0012fea4 #2:0x0012fef8him->income is $58112.00: (*him).income is $58112.00him->favfood is tripe: him->handle.last is Swillbelly

 

结构(fellow)作为函数的参数传递分类 

1:传递结构成员      例如:function(fellow[0].income)
2:传递结构地址      例如:function(&fellow[0])
3:把结构作为参数传递  例如:function(fellow[0])
4:把一个结构赋值给另外一个结构 例如:fellow[0]=fellow[1]
5:结构不能直接赋值给指针(需&取地址),而数组可以直接赋值给指针   例如:p=&fellow[0] 或 p=数组名