09/02/20 09:02:10
/* プログラム① */
#include <stdio.h>
int main( void )
{
int *x,*y;
printf("%d\n",(&y-&x)); /* ここでの表示結果は"1" */
return 0;
}
//------------------------------------------------------
/* プログラム② */
#include <stdio.h>
int main( void )
{
int *x,*y;
printf("%d\n",sizeof(&y-&x)); /* ここでの表示結果は"4" */
return 0;
}
//-------------------------------------------------------
プログラム②ではsizeof演算子を付けて
望んでいた結果の"4"が出力されます。
何故、プログラム①では"1"が出力されるのでしょうか?
コンパイラは「Microsoft(R)32-bit C/C++ Standard Compiler」です。