using unallocated memory without error?

前端 未结 5 1574
礼貌的吻别
礼貌的吻别 2020-12-06 18:37

Why does that work?

#include 
using namespace std;

int main() {
    float* tab[3];

    int i = 0;
    while(i < 3) {
        tab[i] = ne         


        
5条回答
  •  天涯浪人
    2020-12-06 18:40

    While the other answers, with the exception of Mark's, are not wrong they are not exactly right either. What you are doing by accessing data past the end of what you've explicitly allocated in your program is causing "undefined behavior". It can do anything, including "work".

    Steve's answer didn't exist when I began writing this.

提交回复
热议问题