プロが教えるわが家の防犯対策術!

下記のとおりに記述した場合、pには何が入るのでしょうか?
ポインタのポインタアドレスが格納されてるような気がしますが。

int **p;
p = new p *;

A 回答 (1件)

gccで実験。


> cat a.cpp
int main( int argc, char *argv[] ){
int **p;
p = new p *;
}
> g++ a.cpp
a.cpp: In function 'int main(int, char**)':
a.cpp:3: error: expected type-specifier before 'p'
a.cpp:3: error: cannot convert 'int*' to 'int**' in assignment
a.cpp:3: error: expected `;' before 'p'

本当に質問文どおりだとすると「格納されるってレベルじゃねーよ」って事かも。
ちなみにgccだとtypeof演算子が使えるので、以下はOK:
p = new typeof *p;
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!