A conversion operator which converts the current String instance into raw C-style. string oftype const char*.

题目

A conversion operator which converts the current String instance into raw C-style. string of

type const char*.


相似考题
参考答案和解析
正确答案:
 
更多“A conversion operator which converts the current String instance into raw C-style. string oftype const char*.”相关问题
  • 第1题:

    在某类的公共部分有声明string operator++( );和string operator++(int);则说明

    A.string operator++( );是前置自增运算符声明

    B.string( )perator++( );是后置自增运算符声明

    C.string operator++(int);是前置自增运算符声明

    D.两条语句无区别


    正确答案:A
    解析:在重载单操作符的过程中,++既可以是前缀运算符,又可以是后缀运算符,C++规定重载后缀++时必须多一个虚拟参数int,则不带虚拟参数int的为前缀运算符。

  • 第2题:

    Operator overloading operator+= which appends another String instance into current String

    instance.


    正确答案:
     

  • 第3题:

    已知类 String 的原型为

    class string

    {

    public:

    string(const char *str=null);//普通构造函数

    string(const string &other);//拷贝构造函数

    ---string(void);

    string &operate=(const string &other);//赋值函数

    private:

    char * m-data;//用于保存字符串

    };

    请编写 string 的上述4 个函数


    正确答案:
     

  • 第4题:

    编写类 String 的构造函数、析构函数和赋值函数

    已知类 String的原型为:

    class String

    {

    public:

    String(const char *str = NULL); // 普通构造函数

    String(const String &other); // 拷贝构造函数

    ~ String(void); // 析构函数

    String & perate =(const String &other); // 赋值函数

    private:

    char *m_data; // 用于保存字符串

    };

    请编写 String的上述 4 个函数。


    正确答案:
     

  • 第5题:

    下面哪个是main()方法的合法参数()

    A、char args[]

    B、char args[][]

    C、String arg[]

    D、String args


    答案:D

  • 第6题:

    语句()能正确完成赋字符串的功能。

    • A、chars[4];s[0]=“string”
    • B、char*s;get(s)
    • C、char*s[]=“string”
    • D、char*s;strcpy(s,“string”)

    正确答案:C

  • 第7题:

    Given that c is a reference to a valid java.io.Console object, which two code fragments read a line of text from the console?()

    • A、String s = c.readLine();
    • B、char[ ] c = c.readLine();
    • C、String s = c.readConsole();
    • D、char[ ] c = c.readConsole();
    • E、String s = c.readLine("%s", "name ");
    • F、char[ ] c = c.readLine("%s", "name ");

    正确答案:A,E

  • 第8题:

    下面正确声明一个一维数组的是()。

    • A、String [] a
    • B、String a[]
    • C、char a[][]
    • D、String a[10]

    正确答案:A,B

  • 第9题:

    Which two create an instance of an array?() 

    • A、 int ia = new int [15];
    • B、 float fa = new float [20];
    • C、 char ca = “Some String”;
    • D、 Object oa = new float[20];
    • E、 Int ia = (4, 5, 6) (1, 2, 3)

    正确答案:A,D

  • 第10题:

    Which expressions are correct to declare an array of 10 String objects? ()   

    • A、 char str[];
    • B、 char str[][];
    • C、 String str[];
    • D、 String str[10];

    正确答案:C

  • 第11题:

    多选题
    Which expressions will evaluate to true if preceded by the following code?()   String a = "hello";   String b = new String(a);   String c = a;   char[] d = { ’h’, ’e’, ’l’, ’l’, ’o’ };
    A

    (a == Hello)

    B

    (a == b)

    C

    (a == c)

    D

    a.equals(b)

    E

    a.equals(d)


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

  • 第12题:

    多选题
    String s= "hello";     String t = "hello";  char c[] = {’h’,’e’,’l’,’l’,’o’} ;     Which return true?()
    A

    s.equals(t);

    B

    t.equals(c);

    C

    s==t;

    D

    t.equals(new String(hello));

    E

    t==c;


    正确答案: E,A
    解析: 这个在前面第10题的equals()方法和==操作符的讨论中论述过。==操作符比较的是操作符两端的操作数是否是同一个对象,而String的equals()方法比较的是两个String对象的内容是否一样,其参数是一个String对象时才有可能返回true,其它对象都返回假。需要指出的是由于s和t并非使用new创建的,他们指向内存池中的同一个字符串常量,因此其地址实际上是相同的(这个可以从反编译一个简单的测试程序的结果得到,限于篇幅不列出测试代码和反编译的分析),因此答案c也是正确的。

  • 第13题:

    下列( )语句是声明一个含有10个String对象的数组。

    A.char str [];

    B.char str [] [];

    C.String str[]=new String[10];

    D.String str[10];


    正确答案:C

  • 第14题:

    已知String类定义如下:

    class String

    {

    public:

    String(const char *str = NULL); // 通用构造函数

    String(const String &another); // 拷贝构造函数

    ~ String(); // 析构函数

    String & perater =(const String &rhs); // 赋值函数

    private:

    char *m_data; // 用于保存字符串

    };

    尝试写出类的成员函数实现。


    正确答案:

     

    String::String(const char *str)
    {
    if ( str == NULL ) //strlen在参数为NULL时会抛
    异常才会有这步判断
    {
    m_data = new char[1] ;
    m_data[0] = '\0' ;
    }
    else
    {
    m_data = new char[strlen(str) + 1];
    strcpy(m_data,str);
    }
    }
    String::String(const String &another)
    {
    m_data = new char[strlen(another.m_data) + 1];
    strcpy(m_data,other.m_data);
    }
    String& String::operator =(const String &rhs)
    {
    if ( this == &rhs)
    return *this ;
    delete []m_data; //删除原来的数据,新开一块内

    m_data = new char[strlen(rhs.m_data) + 1];
    strcpy(m_data,rhs.m_data);
    return *this ;
    }
    String::~String()
    {
    delete []m_data ;
    }

  • 第15题:

    下列程序执行后,屏幕上显示的应是 public class Testyyy {public static void main(String[]args) {char charl[]={,'t' 'e''s],'t'}; char char2[]={'t','e','s','t','1'}; String s1=new String(char1); String s2=new String(char2,0,4); System.out.println(s1.equals(s2)); } }

    A.true

    B.假

    C.test

    D.编译错误


    正确答案:A
    解析:①可以通过字符数组来生成一个字符申对象:String(char[]value);String(charC[]value,intstartIndex,intnumChars);其中,startIndex指定字符串在数组中的起始下标,numChars表示字符个数。②测试字符串是否相等,可用equals()方法,两串相等则返回true,否则返回false。

  • 第16题:

    在某类的公共部分有声明string operator++();和string operator++(int);则说明

    A.string operator++();是前置自增运算符声明

    B.string operator++();是后置自增运算符声明

    C.string operator++(int); 是前置自增运算符声明

    D.两条语句无区别


    正确答案:A
    解析:在重载单操作符的过程中,对于像++和-这样的操作符,不易区分属于前置还是后置,因此C++规定了用一个虚的形参来区分前置和后置。

  • 第17题:

    下面的程序执行后,屏幕上显示的应是 public class Exam{ public static void main(String[]args){ char char1[]='t','e','s','t'}; char char2[]={'t','e','s','t','1',}; String sl=new String(char1); String s2=new String(char2,0,4); System.out.println(S1.equals(s2)); } }

    A.真

    B.假

    C.test

    D.编译错误


    正确答案:A
    解析:本题考查考生对字符数组的理解。首先可以通过字符数组宋生成一个字符串对象:String(char[]value)和String(char[]value,int startIndex,int numChars),其中, startIndex指定字符串在数组中的起始下标,numChars表示字符个数。然后再测试字符串是否相等,可调用equals()方法,两个字符串相等则返回true,否则返回false。题目中s1和s2都是“test",所以最后返回是true,选项A正确。

  • 第18题:

    Which expressions will evaluate to true if preceded by the following code?()   String a = "hello";   String b = new String(a);   String c = a;   char[] d = { ’h’, ’e’, ’l’, ’l’, ’o’ };  

    • A、(a == "Hello")
    • B、(a == b)
    • C、(a == c)
    • D、a.equals(b)
    • E、a.equals(d)

    正确答案:C,D

  • 第19题:

    在VB语言中,下列定义变量语句格式正确的是()。

    • A、Dim As String xuehao
    • B、Dim xuehao As String
    • C、Dim String As xuehao
    • D、Const xuehao As String

    正确答案:B

  • 第20题:

    下列哪个语句是声明了一个含有10个string对象的数组()。

    • A、char str[];
    • B、char str[][];
    • C、string str[]=newstring[10];
    • D、string str[10];

    正确答案:C

  • 第21题:

    String s= "hello";     String t = "hello";  char c[] = {’h’,’e’,’l’,’l’,’o’} ;     Which return true?()   

    • A、 s.equals(t);
    • B、 t.equals(c);
    • C、 s==t;
    • D、 t.equals(new String("hello"));
    • E、 t==c;

    正确答案:A,C,D

  • 第22题:

    Given that c is a reference to a valid java.io.Console object,which two code fragments read a line of textfrom the console?()

    • A、String s = c.readLine();
    • B、char[] c = c.readLine();
    • C、String s = c.readConsole();
    • D、char[] c = c.readConsole();
    • E、String s = c.readLine("%s", "name ");

    正确答案:A,E

  • 第23题:

    单选题
    Which expressions are correct to declare an array of 10 String objects? ()
    A

     char str[];

    B

     char str[][];

    C

     String str[];

    D

     String str[10];


    正确答案: A
    解析: 严格来说这个题目没有给出一个正确的答案,唯一比较正确的是c,而完全满足题目要求的应该是:String str[]=new String[10]; 注意答案d的形式是不对的,这和c++也是不同的。