+ 5

No Output! Why?

Why these codes have no output?! #include <iostream> using namespace std; int main() { int score = 5; int *add; *add= score; cout << &score << endl; cout << *add<< endl<< add << endl<<*&score; delete &score; return 0; }

23rd Oct 2016, 7:24 AM
Nima J.
Nima J. - avatar
5 Answers
+ 4
@lucasfid telegram id
29th Mar 2017, 5:11 PM
Nima J.
Nima J. - avatar
+ 3
#include <iostream> using namespace std; int main() { int score = 5; int *add; add= new int(score); cout << &score << endl; cout << *add<< endl<< add << endl<<*&score; delete add; return 0; }
23rd Oct 2016, 9:29 AM
Zen
Zen - avatar
+ 1
you have forgotten & symbol before score in *add= score; which means you're trying to allocate a memory address explicitly, to be 5. and I don't think there will be any memory block with this unique address(at least, I don't know). make it into *add = &score;
30th Mar 2017, 9:02 AM
ram kumar
ram kumar - avatar
+ 1
its obvious that you made a mistake by use a int poiner without initial it.
24th Apr 2017, 7:24 AM
killer2
0
Tip:Obvious that you created a int pointer without initial it.
28th Apr 2017, 10:38 AM
mei
mei - avatar