niusouti.com
参考答案和解析
正确答案:D
更多“若有一下程序段int *ptr,x,y=11;ptr=&x;*ptr=10;x=*ptr+y;执行该程序段后,x的值是 ______。A. ”相关问题
  • 第1题:

    设有如下的程序段: char str[]="HelloWorld"; char*ptr; ptr=str; 执行上面的程序段后,*(ptr+10)的值为( )。

    A.'\0'

    B.'0'

    C.不确定的值

    D.'0'的地址


    正确答案:A
    解析:本题涉及字符数组和指针两个知识点:①在C语言中,字符数组在存放字符串时会自动在末尾加上'\0',所以题中数组str有11个元素;②ptr指向数组str的首地址,ptr+10是指向str[10],*(ptt+10)是引用str[10]的值(即结束符'\0')。

  • 第2题:

    设有下列的程序段: char str[]="HelloWorld"; char*ptr; ptr==str; 执行上面的程序段后,*(ptr+10)的值为( )。

    A.'\0'

    B.'0'

    C.不确定的值

    D.'0'的地址


    正确答案:A
    解析:本题涉及字符数组和指针两个知识点:①在C语言中,字符型数组在存放字符串时会自动在末尾加上'\0',所以题中数组str有11个元素;②ptr指向数组str的首地址,ptr+10是指向str[10],*(ptr+10)是引用str[10]的值。

  • 第3题:

    执行以下程序段后,y的值是()。 int a[ ]={1,3,5,7,9}; int x=0,y=1, *ptr; ptr=&a[1]; while(!x) { y+=*(ptr+x); x++; }

    A.1

    B.2

    C.4

    D.24


    B变量j只接收输入数据的前两位,从第三位开始直到空格之间的输入整数都会被保存到浮点型变量y中。

  • 第4题:

    分析下列程序,并写出运行结果【】。 include voidmain(){ int x[10]: int i=5,*ptr=x;

    分析下列程序,并写出运行结果【 】。

    include<iostream.h>

    void main(){

    int x[10]:

    int i=5,*ptr=x;

    *(ptr+i)=10;

    cout<<x[i]<<end1;


    正确答案:10
    10

  • 第5题:

    有如下程序:include using namespace std;class shapes{protected: int x, y;public:

    有如下程序: #include <iostream> using namespace std; class shapes { protected: int x, y; public: void setvalue(int d, int w=O) { x=d; y=w; } virtual void disp()=O; }; class square : public shapes { public: void disp () { cout<<x*y<<end1; } }; int main ( ) { shapes *ptr; square s1; ptr=&s1; ptr->setvalue (10, 5) ;ptr->disp(); return 0; } 执行上面的程序将输出( )。

    A.50

    B.5

    C.10

    D.15


    正确答案:A
    解析:本题中基类shapes是一个抽象类(拥有纯虚函数disp())。在主函数中定义了抽象类的对象指针ptr,并给它赋值派生类square的对象s1,然后进行赋值和输出的操作。