c++ function return

Jan 31, 2018 at 4:33am
#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 Jan 31, 2018 at 4:34am
Jan 31, 2018 at 5:05am
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.