我有简单的测试程序
#include <stdio.h>
int main( int argc , char* argv[] )
{
unsigned int number=2048;
char* cpOut;
char cOut[4];
cpOut=(char*)&cOut[0];
printf("cOut address= %x \n",&cOut[0]);
printf("cpOut address = %x \n",cpOut);
sprintf(&cOut[0],"%d \n", number);
printf("cOut address= %x \n",&cOut[0]);
printf("cpOut address = %x \n",cpOut);
};
Run Code Online (Sandbox Code Playgroud)
在Linux上测试运行,gcc 4.3.4:
user@server /tmp $ ./a.out
cOut address= f9f41880
cpOut address = f9f41880
cOut address= f9f41880
cpOut address = f9f41880
Run Code Online (Sandbox Code Playgroud)
在Solaris 10,Sun C++ 5.10上运行测试:
bash-3.00$ ./a.out
cOut address= 8047488
cpOut address = 8047488
cOut address= 8047488
cpOut address …Run Code Online (Sandbox Code Playgroud)