|
刚刚跟你说起那个缓冲区溢出……写了点代码,如今一写就停不下来了……………………
再送你个代码:
[code:1]
#include <stdio.h>
int main()
{
int i;
char a;
char *s;
int j;
i=0;
scanf("%d",&a);
printf("the value of i is:%d\n",i);
s=(char *)&i;
s--;
printf("now, the address of a is:%x\n",&a);
printf("Address\t\t\tvalue\n");
for(j=0;j<5;j++,s++)
printf("%x\t\t%2x\n",s,(int)*s);
return 0;
}
[/code:1]
hoho~~运行结果:
[code:1]
[monnand@monnand test]$ gcc 1test.c
[monnand@monnand test]$ ./a.out
-1
the value of i is:16777215
now, the address of a is:bffff8f3
Address value
bffff8f3 ffffffff
bffff8f4 ffffffff
bffff8f5 ffffffff
bffff8f6 ffffffff
bffff8f7 0
[monnand@monnand test]$
[/code:1]
再来一个:
[code:1]
[monnand@monnand test]$ ./a.out
-2
the value of i is:16777215
now, the address of a is:bffff8f3
Address value
bffff8f3 fffffffe
bffff8f4 ffffffff
bffff8f5 ffffffff
bffff8f6 ffffffff
bffff8f7 0
[monnand@monnand test]$
[/code:1]
偶说这么多,你到底明白没有阿??? |
|