c++ function return

#include<iostream>
using namespace std;

class test{
public:
test();
~test();
int a = 0;
};

test* GetTest(){ }
int main(){

test* temp = GetTest();
cout<<temp->a<<endl;
}


temp is not NULL!! why?
Last edited on
why would it be?

you don't set anything to null anywhere.

temp is pointing to a random memory location; it may work and it may crash. If you want something to be null or any other value, you have to explicitly assign it that way. Here, get test would return null if you wanted temp to be null.


Topic archived. No new replies allowed.