Prozix
New Member
- Reaction score
- 7
Hello,
I am confused.
I've made two functions:
now here's how I tried to use them:
I haven't got a clue why my program crashes. I'm really really sad
I am confused.
I've made two functions:
Code:
void Test1(int * i){
i = new int;
*i = 1;
}
int * Test2(){
int * i = new int;
*i = 1;
return i;
}
now here's how I tried to use them:
Code:
int main(){
int * i;
Test1(i);
cout<<*i<<endl; //big fat runtime error
}
int main(){
int * i = Test2();
cout<<*i<<endl; //good
}
int main(){
int * i;
{
i = new int;
*i = 1;
}
cout<<*i<<endl; //works too but it's the same as the first try when you completely inline Test1(i);
}