易截截图软件、单文件、免安装、纯绿色、仅160KB

C 程序问题 (三) - C/C++ / C语言

问题一:
在对齐为4的情况下
struct BBB
{
long num;
char *name;
short int data;
char ha;
short ba[5];
}*p;
p=0x1000000;
p+0x200=____;
(Ulong)p+0x200=____;
(char*)p+0x200=____;
假设在32位CPU上,
sizeof(long) = 4 bytes
sizeof(char *) = 4 bytes
sizeof(short int) = sizeof(short) = 2 bytes
sizeof(char) = 1 bytes

问题二:
代码:
void print_array()
{
int num_array[5] = {5,7,2,3,9};
a = num_array;
int i = 0;

while(i<5)
{
printf("%d\n", *a++);
i++;
}
i = 0;
while(i<5)
{
printf("%d\n", *(a+i));
i++;
}

};
结果:(打印出)
5
7
2
3
9
1245056
4198676
1244940
2367460
1243068
问题:为什么当i=0,1,2,3,4的时候,*(a+i)和*a++(连续循环5次)结果不一致呢?原因在哪里呢?请高手指点。谢谢!!!
不好意思,各位。
a = num_array; 写错了
应该是 int *a = num_array;

问题二:
i = 0; 
a = num_array; // 加上这一行结果就一致了
while(i <5) 

printf("%d\n", *(a+i));

问题二: *a++那个循环之后,a已经被移动到num_array的后边去了

问题一:
(Ulong)p+0x200= 0x1000200; p被转换成整数,所以按照整数做加法
(char*)p+0x200= 0x1000200; p被转换成char指针,sizeof(char)是1

p+0x200= (unsigned long)0x100000


相关问答:

C 程序问题 (二) - C/C++ / C语言

问一下:
#include <stdio.h>
int main()
{
  char x, y, z;
  int i;
  int a[16];
  for(i=0; i<=16; i++)
  {
  a[i] = 0;
  ......

C盘上多出2G内容

C盘上多的文件名为:dosh , Recycled ,System Volum information, AUTOEXEC.BAT, BOOT.INT , bootfoot.bin, CONFIG.SYS,IO.SYS, MSDOS.SYS, DETECT.COM ,ntldr, pagefile.sys;
而且每个盘上都有这些文件:RECYCLER ......

linux环境下gethostbyname函数问题 - C/C++ / C语言

写了个测试程序如下
   
  struct hostent *hp; 
char AlarmDevIP[20];  
  int x2;

hp = gethostbyname("www.google.com");
if (hp)
{ ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号