下面程序错误的语句是 ① include ② void main( ) ③ { ④ int * p=new int[1] ; ⑤ p下面程序错误的语句是① #include<iostream.h>② void main( )③ {④ int * p=new int[1] ;⑤ p=9;⑥ cout < < * p < <endl;⑦ delete[ ] p;⑧ }A.④B.⑤C.⑥D.⑦

题目
下面程序错误的语句是 ① include ② void main( ) ③ { ④ int * p=new int[1] ; ⑤ p

下面程序错误的语句是

① #include<iostream.h>

② void main( )

③ {

④ int * p=new int[1] ;

⑤ p=9;

⑥ cout < < * p < <endl;

⑦ delete[ ] p;

⑧ }

A.④

B.⑤

C.⑥

D.⑦


相似考题
更多“下面程序错误的语句是 ① #include<iostream.h> ② void main( ) ③ { ④ int * p=new int[1] ; ⑤ p ”相关问题
  • 第1题:

    下面程序运行时输出结果为【】。 include include class Rect { public: Rec

    下面程序运行时输出结果为【 】。

    include<iostream.h>

    include<malloc.h>

    class Rect

    {

    public:

    Rect(int1,int w)(length=1;width=w;)

    void Print(){cout<<"Area:"<<length *width<<endl;)

    void *operator new(size-t size){return malloc(size);}

    void operator delete(void *p){free(p)

    private:

    int length,width;

    };

    void main()

    {

    Rect*p;

    p=new Rect(5,4);

    p->Print();

    delete p;

    }


    正确答案:Area:20
    Area:20

  • 第2题:

    下面程序段中的错误语句是 ______。 class M{ int i; public: void ~AA(int); AA *p; void AA(); void AA(int x){i=x;}; };

    A.AA *p;

    B.void ~AA(int);

    C.void AA(int);

    D.void AA(int x){i=x;};


    正确答案:B

  • 第3题:

    下面程序错误的语句是①include ②void main()③{④int * p=new int[1]⑤p=9⑥cout<<* p<

    下面程序错误的语句是

    ①#include<iostream.h>

    ②void main()

    ③{

    ④ int * p=new int[1]

    ⑤ p=9

    ⑥ cout<<* p<<end1;

    ⑦ delete []p;

    ⑧}

    A.④

    B.⑤

    C.⑥

    D.⑦


    正确答案:B
    解析:本题考查的是指针的使用,p是指向int型的指针,若想给它指向的元素赋值,应使用*符号,直接赋值相当于改变了原来p存储的地址。

  • 第4题:

    以下程序段中,能够通过调用函数fun,使main函数中的指针变量p指向一个合法的整型单元的是______。

    A.main() { int *p; fun(p); …… } int fun(int *p) {int s; p=&s;}

    B.main() { int *p; fun(&p); …… } int fun(int **p) {int s; *p=&s;}

    C.# include<stdlib. h> main() {int *p; fun(&p); …… } int fun(int **p) {*p=(int *)malloc(2);}

    D.# include<stdlib. h> main() { int *p; fun(p); …… } int fun(int *p) {p=(int *)malloc(sizeof(int));}


    正确答案:C
    解析:选项A和B中p指向局部变量s的地址,退出函数fun后,该局部变量也被释放,不能使p指向一个整型单元地址;选项D中通过malloc函数分配一个整型地址,但不能被返回到main函数中,因为指针参数指向的地址不能被改变;选项C中,p是指向指针的指针,函数fun改变的是其指向的内容,而不是其地址。

  • 第5题:

    以下程序段中,能够通过调用函数fun,使main函数中的指针变量p指向一个合法的整型单元的是

    A.main() { int*p; fun(p); … } int fun(int*p) {int s; p=&s; }

    B.main { int *p; fun(&p); … } int fun(int**p) {int s; *p=&s; }

    C.#include <stdlib.h> main() { int *p; fun(&p); … } int fun(int**p) {*p=(int*)malloc(2); }

    D.#include <stdlib.h> main() { int *p; fun(p); … } int fun(int *p) {p=(int*)malloc(sizeof(int));}


    正确答案:C