鱼C论坛

 找回密码
 立即注册
查看: 3057|回复: 3

C视频54的结构变量指针的简单例子,哪里出问题了。

[复制链接]
发表于 2011-10-2 12:53:12 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 ZPCG 于 2011-10-3 01:20 编辑
  1. #include <stdio.h>

  2. struct stu
  3. {
  4. int num;
  5. char *name;
  6. char sex;
  7. double score;
  8. } boy1 = {102, "jame", "m", 98.7};

  9. void main()
  10. {
  11. struct stu *pstu;
  12. pstu = &boy1;

  13. printf("num = %d name = %s sex = %c score = %lf\n", boy1.num, boy1.name, boy1.sex, boy1.score);

  14. printf("num = %d name = %s sex = %c score = %lf\n", (*pstu).num, (*pstu).name, (*pstu).sex, (*pstu).score);

  15. printf("num = %d name = %s sex = %c score = %lf\n", pstu->num, pstu->name, pstu->sex, pstu->score);
  16. }
复制代码
结果的sex 是空的,可我这个对照了视频的例子,都一样的,麻烦大家帮我解释一下。
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-10-2 13:21:16 | 显示全部楼层
  1. struct stu
  2. {
  3. int num;
  4. char *name;
  5. char sex;
  6. double score;
  7. } boy1 = {102, "jame", 'm', 98.7};   //这里的char sex 是字符,不是字符串,所以定义m不能用双引号,只能用单引号。
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2011-10-2 13:56:24 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-10-2 14:01:17 | 显示全部楼层
ZPCG 发表于 2011-10-2 13:56
爱死你了,不说其他的,亲一个!

呃,你不会喜欢男性吧!~  


嘿嘿,来,我也亲一个。。{:2_32:}
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-8 16:19

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表