• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
爱白菜的小昆虫
博客园    首页    新随笔    联系   管理    订阅  订阅

C/C++ 结构体 函数传递

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 struct student{
 5     int num;
 6     char str[20];
 7     double dec;
 8 };
 9 
10 void scan(struct student *stu){
11 //    scanf("%d%s%lf", &stu->num, stu->str, &stu->dec);
12     scanf("%d%s%lf", &(*stu).num, (*stu).str, &(*stu).dec);//.运算符优先级大于*
13 }
14 
15 void print(struct student stu){
16     printf("%d %s %lf\n", stu.num, stu.str, stu.dec);
17 }
18 
19 int main(){
20 
21     struct student stu;
22     
23     scan(&stu);
24     print(stu);
25 
26     return 0;
27 }
28 /*
29 20 字符串 20.02
30 */

 

posted @ 2016-12-11 03:56  爱白菜的小昆虫  阅读(1467)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3