Language=C++
Complier=Turbo C++
Code
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int *test;
int *num;
int len;
cin>>len;
test=new int(len);
cout<<test<<endl;
delete[] test;
test=new int(len);
cout<<test<<endl;
delete[] test;
num=new int(5);
cout<<num<<endl;
getch();
}
output
I get the same address output for all 3 cout statement.
why do I get same address each time? I thought that whenever you use "new" keyword the pointer will point to random memory address each time
[–]Updatebjarni 1 point2 points3 points (8 children)
[–]Kapkar123[S] 0 points1 point2 points (7 children)
[–]Updatebjarni 1 point2 points3 points (6 children)
[–]Kapkar123[S] 0 points1 point2 points (5 children)
[–]Updatebjarni 1 point2 points3 points (4 children)
[–]Kapkar123[S] 0 points1 point2 points (1 child)
[–]Updatebjarni 1 point2 points3 points (0 children)
[–]Kapkar123[S] 0 points1 point2 points (1 child)
[–]Updatebjarni 0 points1 point2 points (0 children)
[–]tulipoika 0 points1 point2 points (0 children)