有如下程序: #include <iostream> using namespace std; int main( ){ int*P; *P=9; cout<<"The value at P:"<<*P: retu

admin2010-12-16  13

问题 有如下程序:    #include <iostream>    using namespace std;    int main( ){    int*P;    *P=9;    cout<<"The value at P:"<<*P:    return 0;    }    编译运行程序将出现的情况是

选项 A、编译时出现语法错误,不能生成可执行文件
B、运行时一定输出:The value at P:9
C、运行时一定输出:The value at P:*9
D、运行时有可能出错


答案D

解析 int*p;指针变量定义时没有被初始化,也没有指向具体的地址,所以在后面打印时报错。应当做如下初始化:
   int*p=new int( );
转载请注明原文地址:https://kaotiyun.com/show/6QVp777K
0

最新回复(0)