Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Given the following code:
int number = 49;

what will the output be after the following statements are executed?

C++
if(number >= 50)
cout << "yes" << endl;
cout << number = number + 1;


[added]
What will be the output? 50 or Yes 50?
[/added]

What I have tried:

C++
#include <iostream>
using namespace std;

int main ()

{
    int number = 49;

    if ( number >= 50)
    {
        cout << "Yes " << endl;
        cout << number = number + 1;
    }

}
Posted
Updated 9-Aug-17 13:10pm
v2

Quote:
cout << number = number + 1;
This statement is wrong (as the compiler noticed :-) ), because the insertion operator has higher precedence than the assignment one.



The following program
C++
#include <iostream>
using namespace std;

int main()
{
  int number = 49;

  if ( number >= 50)
    cout << "Yes " << endl;
  cout << (number = number + 1);
}


outputs just 50.
 
Share this answer
 
The output od this code:
C++
#include <iostream>
using namespace std;
int main ()
{
    int number = 49;
    if ( number >= 50)
    {
        cout << "Yes " << endl;
        cout << (number = number + 1);
    }
}

is nothing as I understand this code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900