0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C > sizeof(int)とsizeof(int *) on 64bit machine > int*は8バイト / intは決まっていない

Last updated at Posted at 2016-09-01

@Sally-E さんの記事で分からなかったint func()内の以下の処理が2となる理由。

num = sizeof(array)/sizeof(array[0]); 

これが2になるためには @shiracamus さんのコメントにあるように以下となる

  • int *は8バイト
  • int は4バイト

stackoverflowの記事を見つけた
http://stackoverflow.com/questions/20721294/size-of-int-and-sizeof-int-pointer-on-a-64-bit-machine

answered Dec 21 '13 at 16:56
Rahul Tripathi

Size of a pointer should be 8 byte on any 64-bit C/C++ compiler, but the same is not true for the size of int.

64bit OSではint *は8バイト固定だが、intは8固定とは限らない(OSの扱いやすいサイズになる)。

勉強になりました。

0
1
7

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?