Difference between dereferencing NULL pointer and uninitialised pointer

前端 未结 3 883
傲寒
傲寒 2020-12-22 14:01

On code blocks(C++)

#include
using namespace std;
int main(){
    int *p;
    cout<<*p;
}

produces garbage value

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-22 14:47

    In the first code as we are not setting the pointer it is taking random value address... Which may have some garbage value. But in second case pointer is not pointing to any address so obviously it will fail

提交回复
热议问题