63 845
Assignments Done
99,2%
Successfully Done
In August 2018

Answer to Question #11247 in C++ for Chad Dylan Cooper

Question #11247
What is the value of val after the following C++ code executes?

How can I do this?

val = 7;
switch (val % 4)
{
case 3:
val = val + 3;
case 1:
val++;
break;
case 5:
val = val + 5;
case 4:
val = val + 4;
default;
val--;
Expert's answer
#include <iostream>
using namespace std;
int main()
{
int val
= 7;
switch (val % 4)
{
case 3:
val = val + 3; // this,
so getting val = 7 + 3 = 10
case 1:
val++; // this ('cause
there were no break in case 3), so
getting val = 10 + 1 = 11

break;
case 5:
val = val + 5;
case 4:
val
= val + 4;
default:
val--;
}
cout << val <<
endl;
return 0;
}

Result: 11.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions