cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
c++ function return
c++ function return
Jan 31, 2018 at 4:33am UTC
chunfeng
(1)
#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 UTC
Jan 31, 2018 at 5:05am UTC
jonnin
(11438)
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.