C + + Problem-20140924

Source: Internet
Author: User

From http://zhedahht.blog.163.com/blog/static/25411174201171214133316/

Problem ( ) : What is the printed result of C + + code in operation ?

BOOL Fun1 (char* str)

{

printf ("%s\n", str);

return false;

}

BOOL Fun2 (char* str)

{

printf ("%s\n", str);

return true;

}

int _tmain (int argc, _tchar* argv[])

{

bool res1, res2;

res1 = (Fun1 ("a") && Fun2 ("B")) | | (Fun1 ("C") | | Fun2 ("D"));

Res2 = (Fun1 ("a") && Fun2 ("B")) && (Fun1 ("C") | | Fun2 ("D"));

return res1 | | res2;

}

Answer : Print out 4 lines, respectively a, C, D, a.

return is False,  no matter Func2 (" B ") ,fun1 (" a ") && Func2 (" B ") The result of span lang= "ZH-CN" is False

when calculating Rest2 , first Func1 ("a") prints a line of content. Because Func1 ("a") returns false, as before, Func2 ("B") omits the calculation. Because the result of FUN1 ("a") && Func2 ("B") is false, regardless of the result of FUN1 ("C") && Func2 ("D"), the result of the entire expression is false , so Fun1 ("C") && Func2 ("D") are ignored.

C + + Problem-20140924

Related Article

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.