#include <stdio.h>
#include <stdlib.h>
int main(int args,const char* argv[]){
int x=66;
int y=255;
puts("qssq666");
putchar(x);\\只能放一个字符.
printf("\naddress x %#x",&x);
printf("\naddress y %#x",&y);
printf("\n------\n");
// putchar("y");//为何输出了 \250,参数错了 ,找不到,
putchar('Z');//
printf("\n------\n");
char a[]="nihao\n";
char b[3]={'l','z','\0'};
printf("a=%s b=%s \naddress a %#x\naddress b %#x \n",a,b,a,b);
char c[]="love";
char d[]={'h','e','l','l','o'};// 没有写\n所以会输出hellolove, char d[]={'h','e','l','l','o','\0'}
char e[]={'w','o','r','l','d','\0'};
char f[1]={'m','\n'};//虽然写了,但是申请的就那么多,截断勒,所以还是会往上面找
printf("address c %#x\naddress d %#x \ndstr=[%s]\n",c,d,d);
printf("\n\n[e=%s],f=%s\n",e,f);
return 5;//exit code
}
从图上得出结论,程序是往下开始读取申请的, 其中d变量没有\0
,所以会把继续往下读地址,读到的下一个地址就是c,所以输出了怪异的东西
B
address x 0xefbff64c
address y 0xefbff648
------
Z
------
a=nihao
b=lz
address a 0xefbff641
address b 0xefbff63e
address c 0xefbff639
address d 0xefbff634
dstr=[hellolove]
[e=world],f=mworld
Program ended with exit code: 5