一个循环赋值的问题
我用的是Visual Studio 2017。正常情况下代码如下
程序代码:
#include<stdio.h> #include<conio.h> int main() { char f1_name[4096], f2_name[4096]; unsigned long long *ip1, *ip2, *ipe1 = (unsigned long long*)(f1_name + 4096); ip1 = (unsigned long long*)f1_name; ip2 = (unsigned long long*)f2_name; for (; ip1 < ipe1; ip1++, ip2++) *ip1 = *ip2 = 0; ip1 = (unsigned long long*)f1_name; ip2 = (unsigned long long*)f2_name; for (; ip1 < ipe1; ip1++, ip2++) printf("%llX %llX\n", *ip1, *ip2); return 0; }输出是两列0。
在赋值前加入输出代码后代码如下
程序代码:
#include<stdio.h> #include<conio.h> int main() { char f1_name[4096], f2_name[4096]; unsigned long long *ip1, *ip2, *ipe1 = (unsigned long long*)(f1_name + 4096); ip1 = (unsigned long long*)f1_name; ip2 = (unsigned long long*)f2_name; for (; ip1 < ipe1; ip1++, ip2++) { printf("%llX %llX\n", *ip1, *ip2); }; getchar(); ip1 = (unsigned long long*)f1_name; ip2 = (unsigned long long*)f2_name; for (; ip1 < ipe1; ip1++, ip2++) *ip1 = *ip2 = 0; ip1 = (unsigned long long*)f1_name; ip2 = (unsigned long long*)f2_name; for (; ip1 < ipe1; ip1++, ip2++) { printf("%llX %llX\n", *ip1, *ip2); } return 0; }
为什么在加入代码后输出的第二列不是0,而是一列相同的数字(每次运行不一定一样),例如63006200610060、67006600650064、6B006A00690068?