C_and_CPP 板


LINE

很多基础就不打了,只打一些重点 设环境 x86_32 char* a -> pointer to char int* b -> pointer to int int c[4] -> array of int int (*d)[4] -> pointer to an array of int sizeof(a) = sizeof(b) = 4 sizeof(char) = 1 sizeof(int) = 4 sizeof(c) = 4 * sizeof(int) = 16 sizeof(d) = sizeof(void*) = 4 //设 a = 0x0,b = 0x0 , &c=0x0 a++ 後为0x0 + sizeof(char) = 0x1 b++ 後为0x0 + sizeof(int) = 0x4 c 实质上是 the address of the first element of an array &c 是 a pointer to [an array of int] int *p = c 会被隐型转成 int *p = &c[0] int *p = &c 因为两边型态不同,所以被强制转成 int* c = &c = 0x0 只是型态不同 c 是 int * &c 是 int (*)[4] ------------ 所以回到原文 int*p = &A; 两边的型态一样吗? Ans: 不一样 p 是 a pointer to int &A 是 a pointer to [an array of int] 在 &A = A 的情况下被强制隐性转为 int* 这个特性要注意做指标运算时要注意接下来的 pointer type 是不是你要的 ※ 引述《zzss2003 (brotherD)》之铭言: : 网址: : https://stackoverflow.com/questions/49890211/address-operator-and-array-in-assembly-level : 在Answer里面提到: : The address of & operator allows you to construct a pointer to value from a : variable of same type as value. : 中文翻译:address operator允许你建构一个指标(from一个变数to value,且这个变数有 : 跟value一样的type) : 请问,这一行的意思是不是指,当执行程式这一行时: : p = &var1; : &本身也会占用一个variable的空间(用来放var1的address),然後在把这个address给p? : 接下来,内文提到: : int *p = &A; : 程式在做这行指令时,you are doing an assignment from a pointer to array of int : into a variable of type array of int, which is a different type. : 光看这行英文,哪有different type,一样是array of int啊 : 还是他打错了?应该是from a pointer to int into a variable of type array of int? : 谢谢。 --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 36.227.39.219
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1524404003.A.03A.html ※ 编辑: enonrick (36.227.39.219), 04/22/2018 21:34:06 ※ 编辑: enonrick (36.227.39.219), 04/22/2018 21:36:17
1F:推 zzss2003: 精辟 04/23 09:30
2F:推 KanzakiHAria: 这篇其实有讲清楚了 原PO还是卡住XD 04/23 11:53
3F:推 splasky: 推 04/23 12:04







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Gossiping站内搜寻

TOP