C + + Rectification Textbook Teaching Practice example 1.2 two number and why Sum=a+b;sum value is 65538

Source: Internet
Author: User

Chapter I.

#include <iostream>
using namespace Std;

int main () {
int a,b,sum;
Sum=a+b;
cin>>a>>b;
cout<< "a+b=" <<sum<<endl;
return 0;
}

Reason Sum=a+b; This statement is not in position, and the variable A, B, is added when there is no assignment, beyond the int maximum range. Can only get the maximum value 65538

#include <iostream>
using namespace Std;

int main () {
int a,b,sum;
cin>>a>>b;

Sum=a+b;

cout<< "a+b=" <<sum<<endl;
return 0;
}

C + + Rectification Textbook Teaching Practice example 1.2 two number and why Sum=a+b;sum value is 65538

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.