*new -vs- new

Started by
3 comments, last by sab3156 21 years, 1 month ago
what is the difference between
*new 
and
new 
?? i understand by using the
new 
will be used as pointer allocation, but is it essentially the same as
*new 
??
Air-Conditioners are like computers. They stop working when you open windows.
Advertisement
I imagine that *new would dereference the pointer new returns, and in the process create a memory leak since we have allocated memory with no pointer to delete it with later.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Unless you''ve taken a reference to it, but that''s still a stupid thing to do :
int& i = *new int;...delete &i 


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Not if you use a garbage collector.
I guess you''ve seen this somewhere otherwise you wouldn''t be asking. What was the context you saw it in?


  #include <iostream>int main() {    using std::cout;    using std::endl;    int* sheep = new int(5);    cout << "address of sheep " << sheep << endl;    cout << "number of sheep " << *sheep << endl;//  int dog = *new int(1);// memory leak    int* dog = new int(1);    int spit = *dog;    cout << "address of dog " << dog << endl;    cout << "number of dog " << *dog << endl;    cout << "number of spit " << spit << endl;    cout << "address of spit " << &spit << endl;    delete sheep;    delete dog;}  

This topic is closed to new replies.

Advertisement