Classical C/C ++ interview questions (2)

Source: Internet
Author: User

From: http://hi.baidu.com/qrs1/blog/item/c4b5dbcd0fa0d2590fb345e5.html

 

1. What are output by the following three output statements? [C ease]

Char str1 []= "Abc ";

Char str2 []= "Abc ";

Const char str3 [] = "abc ";

Const char str4 [] = "abc ";

Const char * str5= "Abc ";

Const char * str6= "Abc ";

Cout <boolalpha <(str1 = str2) <endl; // What is output?

Cout <boolalpha <(str3 = str4) <endl; // What is output?

Cout <boolalpha <(str5 = str6) <endl; // What is output?

2. Where can B be implicitly converted to A for non-C ++ built-in types A and B? [C ++ medium]

A:

A. class B: public {......} // The Public B inherits from A and can be indirectly inherited.

B. class B {operator A ();} // B implements implicit conversion to

C. Class A {A (const B &) ;}// a constructor that implements the non-explicit parameter as B (other parameters with default values can be available)

D. A & operator = (const A &); // value assignment operation. Although it is not an authentic implicit type conversion operation, it can barely calculate

3. Are there any problems with the usage of the two sizeof in the following code? [C ease]

Void uppercase (char STR []) // converts lowercase letters in STR to uppercase letters.

{

For (size_t I = 0; I <sizeof (STR)/sizeof (STR [0]); ++ I)

If ('A' <= STR [I] & STR [I] <= 'Z ')

STR [I]-= ('A'-'A ');

}

Char STR [] = "ABCDE ";

Cout <"str character length:" <sizeof (STR)/sizeof (STR [0]) <Endl;

Uppercase (STR );

Cout <STR <Endl;

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.