考慮簡單的代碼: #include "stdio.h"
#define N 10U
int main() {
int a[N] = {0};
unsigned int i = N;
int s = 0;
// Fill a
while(i--)
s += a[i];
printf("Sum is %d\n", s
在討論過程中,我與幾個同事的一天,我扔在一起一段代碼在C++來說明一個內存訪問衝突。 我目前正在慢慢返回到C++的過程中,幾乎完全使用垃圾收集語言,我猜,我失去了觸摸顯示,因爲我一直對我的短暫行爲感到困惑節目展出。 有問題的代碼是這樣: #include <iostream>
using std::cout;
using std::endl;
struct A
{
int v
#include <iostream>
int main()
{
int *ptr = NULL;
// It does not crash
*ptr; --------> Point-1
//But this statment crashed
std::cout<<"Null:"<<*ptr<<"\n"; ------> Point-2