有下列语句:  struct Birthday{public int year;  public int month;   public int day;}; struct Student{ int no;  string name;   int age;  public Birthday bir; };  ……  Student Stu;  如果要把Stu的出生年份赋值为1988,正确的语句是()A、 Stu.bir.year=1988;B、 Stu.year=1988;C、 Stu. Birthda

题目

有下列语句:  struct Birthday{public int year;  public int month;   public int day;}; struct Student{ int no;  string name;   int age;  public Birthday bir; };  ……  Student Stu;  如果要把Stu的出生年份赋值为1988,正确的语句是()

  • A、 Stu.bir.year=1988;
  • B、 Stu.year=1988;
  • C、 Stu. Birthday.year=1988;
  • D、 Student. Birthday.year=1988;

相似考题
参考答案和解析
正确答案:A
更多“有下列语句:  struct Birthday{public int year;  public int month;   public int day;}; struct Student{ int no;  string name;   int age;  public Birthday bir; };  ……  Student Stu;  如果要把Stu的出生年份赋值为1988,正确的语句是()A、 Stu.bir.year=1988;B、 Stu.year=1988;C、 Stu. Birthday”相关问题
  • 第1题:

    已知学生记录描述为:

    struct student

    { int no;

    char name[20],sex;

    struct

    { int year,month,day;

    } birth;

    };

    struct student s;

    设变量s中的"生日"是"1984年11月12日",对"birth"正确赋值的程序段是

    A.year=1984;month=11;day=12;

    B.s.year=1984;s.month=11;s.day=12;

    C.birth.year=1984;birth.month=11;birth.day=12;

    D.s.birth.year=1984;s.birth.month=11;s.birth.day=12;


    正确答案:D

  • 第2题:

    若有以下定义的语句: struct student { int age; int num;}; struct student stu[3]={{1001,20},{1002,19},{1003,21}}; main() { struct student *p; p=stu; …} 则以下不正确的引用是( )。

    A.(p++)->num

    B.p++

    C.(*p).num

    D.P=&stu.age.


    正确答案:D
    解析:结构体成员的引用可以用“结构体变量名.成员名”或者“结构体变量指针->成员名”两种方式来引用。注意:结构体类型的变量、数组和指针变量的定义。

  • 第3题:

    下面结构体的定义语句中,不正确的是______。

    A.structdate { int month; int day; int year; } Struct date datel;

    B.stmctdate { intmonth; int day; int year; } datel;

    C.struct { int month; int day; int year; } date 1;

    D.#define DATE stmct date DATE { int month; int day; int year; }datel;


    正确答案:A

  • 第4题:

    有如下说明和定义语句: struct student { int age; char num{8};}; struct student stu[3]={{20,"200401"},{21,"200402"),{19,"200403"}}; struct student *p=stu; 以下选项中引用结构体变量成员的表达式错误的是( )。

    A.(p++)->num

    B.p->num

    C.(*p).num

    D.stu[3].age


    正确答案:D
    解析:结构体变量也有地址,因此可以把它的地址赋值给一个指针变量,然后通过该指针变量来引用结构体的成员,选项A和选项B就是通过指针变量来引用结构体的成员,故选项A和选项B都正确,也可以通过结构体数组元素的成员引用,选项C和选项D属于这种情况,而在选项D中stu[3].age不正确,因为结构体数组stu共有3个元素,其下标应该为0,1,2。所以,4个选项中选项D符合题意。

  • 第5题:

    有以下说明和定义语句:struct student{int age; char num[8] ;};struct student stu [3] = { { 20, "200401" } , {21, "200402" } , {19, "200403" } };stract student * p = stu;以下选项中引用结构体变量成员的表达错误的是( )。

    A.(p++) ->num

    B.p- >num

    C.( *p).num

    D.stu[3].age


    正确答案:D
    解析:结构体变量的引用有三种形式:结构体变量.成员名;(*p).成员名;P->,成员名。所以选项A),B),C)都是正确的。

  • 第6题:

    某C语言结构体的定义如下。 struct date { int year, month, day; }; struct worklist { char name[20]; char sex; struct date birthday; }person; 若对变量person的出生年份进行赋值,正确的赋值语句是(33)。

    A.year=1976

    B.birthday. year=1976

    C.person. year=1976

    D.person. birthday. year=1976


    正确答案:D
    解析:本试题考查嵌套定义的结构体成员的引用。首先,直接使用结构体成员而无所属关系是一种典型错误,系统将认为它是普通变量而非结构体成员。其次,不论结构体嵌套的层次多少,只能从最外层开始,逐层用“.”运算符展开,注意展开时必须使用变量名而不是结构体名。事实证明,只有这种展开方式才能清楚地说明成员的所属关系。对于试题,若对变量person的出生年份进行赋值,正确的赋值语句是选项D的“person-birthday.year=1976”。

  • 第7题:

    Person p = new Person(“张三”,23);这条语句会调用下列哪个构造方法给属性进行初始化()

    A.public Person(){}

    B.public Person(String name,int age) { this.name = name; this.age = age; }

    C.public Person(int age,String name) { this.age = age; this.name = name; }

    D.public Person(String name) { this.name = name; }


    答案:B
    解析:创建对象时会找到匹配的构造方法给属性进行初始化,由于Person p = new Person(“张三”,23);这条语句中有两个参数,而且第1个参数是String类型的,第2个参数是int类型的,因此会调用B选项中的构造方法。

  • 第8题:

    下列语句段中,正确的是( )。

    A.struct { int x; float y; int a[2]; unsigned b[3]; char name[ 10]; };

    B.struct stu { unsigned a[3]; unsigned b[4]; }x; int *p=& x.a;

    C.street stu { int a; float x[4]; }y={1,1.0}; float data=y.x;

    D.struct nd {int a,b; unsigned c[2]=5; };


    正确答案:A
    解析:本题主要考查的知识点是结构类型的概念和定义,结构定义的一般形式是:struct结构类型名称{数据类型成员名1;数据类型成员名2;…数据类型成员名n;};struct为关键字,是结构的标识符:{}中包围的是组成该结构的成员项;每个成员的数据类型既可以是简单的数据类型,也可以是复杂的数据类型。整个定义作为一个完整的语句,用分号结束。结构类型名称是可以省略的,此时定义的结构称为无名结构。

  • 第9题:

    类Student代码如下:  class Student{    String name;  int age;  Student(String nm){  name = nm; } }  执行语句Student stu = new Student()后,字段age的值是哪项?() 

    • A、 0
    • B、 null
    • C、 false
    • D、 编译错误

    正确答案:D

  • 第10题:

    Given the uncompleted code of a class:     class Person {  String name, department;     int age;  public Person(String n){  name = n; }  public Person(String n, int a){  name = n;  age = a;  }  public Person(String n, String d, int a) {  // doing the same as two arguments version of constructor     // including assignment name=n,age=a    department = d;     }     }  Which expression can be added at the "doing the same as..." part of the constructor?() 

    • A、 Person(n,a);
    • B、 this(Person(n,a));
    • C、 this(n,a);
    • D、 this(name,age);

    正确答案:C

  • 第11题:

    类Student代码如下:D   class Student{   String name;   int age;   Student(String nm){ (构造方法)   name = nm;  }  }   执行语句Student stu = new Student()后,字段age的值是哪项?()

    • A、 0
    • B、 null
    • C、 false
    • D、 编译错误

    正确答案:D

  • 第12题:

    单选题
    有下列语句:  struct Birthday{public int year;  public int month;   public int day;}; struct Student{ int no;  string name;   int age;  public Birthday bir; };  ……  Student Stu;  如果要把Stu的出生年份赋值为1988,正确的语句是()
    A

     Stu.bir.year=1988;

    B

     Stu.year=1988;

    C

     Stu. Birthday.year=1988;

    D

     Student. Birthday.year=1988;


    正确答案: D
    解析: 暂无解析

  • 第13题:

    给出下列的不完整的类代码,则哪个语句可以被加到横线处? ( ) class Person{ String name,department; int age; public Person(String n){name=n;} public Person(String n,int s){name=n; age=a;} public Person(String n,String d,int a){ department=d;______ } }

    A.Person(n,a);

    B.this(Person(n,a));

    C.this(n,s);

    D.this(name,age);


    正确答案:C

  • 第14题:

    下列程序运行后的输出结果是( )。#include#includeusing namespace std;class Person{public:Person(string n):name(n) { cout<<'P'; }private:string name;};class Date{public:Date(int y=2012,int m=12,int d=21):year(y),month(m),day(d) { cout<<'D'; }

    private:int year,month,day;};class Student:public Person{public:Student(string n,int y,int m,int d,char c):birthday(y,m,d),sex(c),Person(n) { cout<<'S'; }private:Date birthday;char sex;};int main(){Student stu1("Zhang",1990,10,1,'F');return 0}

    A. S

    B.PS

    C.DPS

    D.PDS


    参考答案:D

  • 第15题:

    给出下列的不完整的类代码,则下列的( )语句可以加到横线处。 class Person{ String name,department; int age public Person(String n){name=n;} public Person(String n,int a){name=n;age=a;} pubilc Person(String n,String d,int a) { _______________ department=d; } }

    A.Person(n,a);

    B.this(Person(n,a));

    C.this(n,a);

    D.this(name,age);


    正确答案:C

  • 第16题:

    有以下说明和定义语句struct student{ int age; char num[8];};struct student stu[3]={{20,"200401"},{21,"200402"},{10\9,"200403"}};struct student *p=stu;以下选项中引用结构体变量成员的表达式错误的是A.(p++)->num B.p->num C.(*p).num D.stu[3].age


    正确答案:D
    引用形式有以下三种:①结构体变量.成员名;②(*p).成员名;③p→成员名。所以A、B、C答案都是正确的。故本题答案为D。

  • 第17题:

    以下程序的输出结果是______。includestruct stu{int num; char name[10]; int age;};v

    以下程序的输出结果是______。#include<stdio.h>struct stu{ int num; char name[10]; int age;};void fun(struct stu*p){ printf("%s\n",(*p).name);}main(){ struct stu students[3]={ {9801,"Zhang",20}, { 9802,"Wang",19}, { 9803,"Zhao",18} }; fun(students+2);}

    A.Zhang

    B.Zhao

    C.Wang

    D.18


    正确答案:B

  • 第18题:

    给出下列的不完整的类代码,则下列的哪个语句可以加到横线处? class Person { String name,department; int age; public Person( String n ){ name = n;} public Person( String n,int a ) { name = n;age = a;} public Person( String n,String d,int a ) { _____________ department = d; } }

    A.Person(n,a);

    B.this(Person(n,a) );

    C.this(n,a);

    D.this(name,age);


    正确答案:C
    解析:在同一个类的不同构造方法中调用该类的其他构造方法需要使用this(…)的形式,而且必须是在构造方法的第一行调用,这个和普通方法重载调用的方式不同,普通方法可以直接使用方法名加参数来调用,而且调用位置没有限制,因此选项A)是不行的,选项B)的语法就是错误的,选项D)的错误在于在父类型的构造方法被调用前不能引用类的成员。构造方法是一个类对象实例化的开始,因此在构造方法中不能将成员作为参数引用。

  • 第19题:

    下列语句段中,正确的是( )。

    A.street { int x; float y; int a[2]; unsigned b[3]; char name[ 10]; };

    B.struct stu { unsigned a[3]; unsigned b[4]; }x; int *p=& x.a;

    C.stmct stu { int a; float x[4]; }y={1,1.0}; float data=y.x;

    D.struct nd { int a,b; unsigned c[2]=5; };


    正确答案:A
    解析:本题主要考查的知识点是结构类型的概念和定义,结构定义的一般形式是:struct结构类型名称{数据类型成员名1;数据类型成员名2;…数据类型成员名n;};struct为关键字,是结构的标识符:{}中包围的是组成该结构的成员项;每个成员的数据类型既可以是简单的数据类型,也可以是复杂的数据类型。整个定义作为一个完整的语句,用分号结束。结构类型名称是可以省略的,此时定义的结构称为无名结构。

  • 第20题:

    ( 38 )有以下定义和语句

    struct workers

    { int num;char name[20];char c;

    struct

    { int day; int month; int year; } s;

    } ;

    struct workers w,*pw;

    pw = &w;

    能给 w 中 year 成员赋 1980 的语句是

    A ) *pw.year = 198O;

    B ) w.year=1980;

    C ) pw->year=1980;

    D ) w.s.year=1980;


    正确答案:D

  • 第21题:

    数据结构里,struct student { char name[20]; char sex[10]; int age; int score; }; 定义结构体后,定义变量、数组赋值正确的是()。

    • A、struct student s={"张三","男",18,100};
    • B、struct student stu[3]={{"张三","男",18,100},{"李四","男",19,90},{"王五","男",23,97}};
    • C、struct student s={"李四";"女";18;100};
    • D、struct student stu[3]={{"张三",18,"男",100},{"李四",19,"男",90},{"王五",23,"男",97}};

    正确答案:A,B

  • 第22题:

    类Student的声明如下:   package com.school class Student{ String name;  int age;  Student(String name,int age){  //code } void study(String subject){ / /code } }  正确调用方法study(String subject)的是哪项?() 

    • A、Student stu = new Student(“Tom”,23); stu.study(“数学”);
    • B、Student.study(“数学”);
    • C、Student stu = new Student(“Tom”,23); stu.study();
    • D、Student stu = new Student(“Tom”,23); String result=stu.study(“数学”);

    正确答案:A

  • 第23题:

    单选题
    类Student代码如下:D   class Student{   String name;   int age;   Student(String nm){ (构造方法)   name = nm;  }  }   执行语句Student stu = new Student()后,字段age的值是哪项?()
    A

     0

    B

     null

    C

     false

    D

     编译错误


    正确答案: C
    解析: 暂无解析

  • 第24题:

    单选题
    类Student的声明如下:   package com.school class Student{ String name;  int age;  Student(String name,int age){  //code } void study(String subject){ / /code } }  正确调用方法study(String subject)的是哪项?()
    A

    Student stu = new Student(“Tom”,23); stu.study(“数学”);

    B

    Student.study(“数学”);

    C

    Student stu = new Student(“Tom”,23); stu.study();

    D

    Student stu = new Student(“Tom”,23); String result=stu.study(“数学”);


    正确答案: D
    解析: 暂无解析