相同的文件,相同的文件大小,但两种不同的内存大小,为什么?
FILE *fp;
short *originalUnPacked;
short *unPacked;
int fileSize;
fp = fopen(FILENAME, "r");
fseek (fp , 0 , SEEK_END);
fileSize = ftell (fp);
rewind (fp);
originalUnPacked = (short*) malloc (sizeof(char)*fileSize);
unPacked = (short*) malloc (sizeof(char)*fileSize);
printf ( "The UnPacked : %d ", unPacked);
printf ( "The Original UnPacked : %d ", originalUnPacked);
// 上面的打印语句打印两个不同的值,我的问题是为什么?
FILE *fp;
short *originalUnPacked;
short *unPacked;
int fileSize;
fp = fopen(FILENAME, "r");
fseek (fp , 0 , SEEK_END);
fileSize = ftell (fp);
rewind (fp);
originalUnPacked = (short*) malloc (sizeof(char)*fileSize);
unPacked = (short*) malloc (sizeof(char)*fileSize);
printf ( "The UnPacked : %d ", unPacked);
printf ( "The Original UnPacked : %d ", originalUnPacked);
// The above print statement prints two different values ,my question is Why ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你不应该将 Short* 传递给 printf 。它需要一个简单的短路,对吧?
如果你打印一个短*,你不会得到大小,你会得到该内存所在的地址。
I don't think you should be passing short* to printf. It expects a simple short, right?
If you print a short*, you're not getting the size, you're getting the address of where that memory is.