why is cout changing the array value?

Hello!
Version with cout gives completely different result!
Please, how can COUT influence result in main???
MANY THANKS!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  int* po(int b){
int d1;
d1=3*b;
int d2;
d2=d1+5;
int a[3];
a[0]=d1;
a[1]=d2;
a[2]=a[1]+3;
int* p=a;
//cout<<p<<endl;
return p;
}


int main(){
int st=4;
cout<<" main: "<<po(st)<<endl;
int* h;
h=po(st);
cout<<"main: "<<*h<<endl;
return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
int* po(int b){
int d1;
d1=3*b;
int d2;
d2=d1+5;
int a[3];
a[0]=d1;
a[1]=d2;
a[2]=a[1]+3;
int* p=a;
cout<<p<<endl;
return p;
}


int main(){
int st=4;
cout<<" main: "<<po(st)<<endl;
int* h;
h=po(st);
cout<<"main: "<<*h<<endl;
return 0;
}
Last edited on
Topic archived. No new replies allowed.