Question

What is the value of  result after the following code executes?   int a = 60; int b...

What is the value of  result after the following code executes?  
int a = 60;
int b = 15;
int result = 20;
if (a = b)
result *= 3;

30

20

60

10

code will not execute

The numeric data types in C++ can be broken into two general categories which are

integers and floating-point numbers

singles and doubles

real and unreal numbers

numbers and characters

numbers and literals

Which line in the following program will cause a compiler error?
1 #include <iostream>
2 using namespace std;
3
4 int main()
5 {
6 const int MY_VAL = 77;
7 MY_VAL = 99;
8 cout << MY_VAL << endl;
9 return 0;
10 }

line 6

line 8

line 7

line 9

there will be no compiler error

What is the output of the following segment of code if the value  4 is input by the user?
int num;
int total = 10;
cout << "Enter a number from 1 to 10: ";
cin >> num;
switch (num)
{
case 1:
case 2: total = 5;
case 3: total = 10;
case 4: total = total + 3;
case 8: total = total + 6;
default: total = total + 4;
}
cout << total << endl;

23

13

3

0

None of these

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. result = 60, if(a = b) is not a logical decision, it just assignment operation and it would be successful so the result will be multiplied by 3 which makes it value 60 from 20

2. Error on line 7 as the MY_VAL variable is read-only or constant and can not be changed

3. Total = 23, there is no break statement so it started at case 4 but it didn't stop there so next is case 8 and then the default case which increases the value of total by first 3, then 6 then 4 that is total of 13 and the initial value was 10 which makes it 23

If there is any doubt left, please do comment, I will try to get back on to reply as soon as possible

Add a comment
Know the answer?
Add Answer to:
What is the value of  result after the following code executes?   int a = 60; int b...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Given the following function: int fun1(int count){ int Num ; for (i = 0; i <...

    Given the following function: int fun1(int count){ int Num ; for (i = 0; i < count; ++i) { cin >> Value; if (i == 0) Num = Value; else if (Value > Num) Num = Value; } return Num ; } What is the output of the following C++ code segment if the following list is entered? (Input list:  5 -15 -90 -2 -60 -30) int Num = 0 , Value, numValues; cin >> numValues; if (numValues > 0) cout...

  • 51. What is the output of the following code snippet? int number = 0; int ptr_num...

    51. What is the output of the following code snippet? int number = 0; int ptr_num -&number ptr_num 60; number-80 cout < "ptr num << endl b, 60 c. 80 d. the address of number Answer 52. What is the output of the following code snippet? double num-0.0; double* ptr = &num; num = 15.0; ptr ptr 15.0 cout << num <<"ptr <<endl; a. 15 15 b. 15 30 С. 30 15 d. 30 30 Answer: 53. What is the...

  • Question 15 After the following code executes, what is the output if user enters 0? int...

    Question 15 After the following code executes, what is the output if user enters 0? int x =-1; cout << "Enter O or 1:"; cin >> X; if (x) cout << true else cout << false O nothing will be displayed true O false 0

  • 12) 8 pts. Find the errors in the following code fragment and correct them. #i nclude...

    12) 8 pts. Find the errors in the following code fragment and correct them. #i nclude <iostream> using namespace std; double fudge (double s) f return s 2.3; int mainO cout >> "Your original estimate" double estimate; cin >> estimate; cout << endl; for (int 1 = 0;1c3;i++); cout << "EStimate' < fudge(estimate) <<endl Hint: There are 4 syntax errors. There is one error that is syntactically correct but causes the output to not be what you would expect. Once...

  • in c# 1- What is the output for total after the following segment of code executes?...

    in c# 1- What is the output for total after the following segment of code executes? int num = 3, total = 0; switch (num) {                case 1:                case 2:                               total = 5;                               break;                case 3:                               total = 10;                               break;                case 4:                               total = total + 3;                               break;                case 8:                               total = total + 6;                               break;                default:                               total = total + 4;                               break; } WriteLine("The value of total is " + total); The value displayed for total would be ....

  • Suppose that the input is 0 5 6 4 9 8 -1.What is the output of the following code?   in...

    Suppose that the input is 0 5 6 4 9 8 -1.What is the output of the following code?   int num = 0;    int sum;    cin >> sum;   while (num != -1)    { cin >> num; sum = sum + 2 * static_cast<int>(sqrt(num));    } cout << "Sum = " << sum << endl;

  • int num; int total = 0; cout << "Enter a number from 1 to 10."; cin...

    int num; int total = 0; cout << "Enter a number from 1 to 10."; cin >> num; switch (num) {    case 1:    case 2:   total = 5;    case 3:   total = 10;    case 4:   total = total + 3;    case 8:   total = total + 6;    default: total = total + 4; } cout << total; A. 10 B. 0 C. 23 D. 3 E. None of these

  • Example (4) Trace the following program and find the output >> SOURCE CODE #include <iostream.h> int...

    Example (4) Trace the following program and find the output >> SOURCE CODE #include <iostream.h> int main0 // define two integers int x-3; int y = 4; //print out a message telling which is bigger if (x >y) i cout << "x is bigger than y" << endl: else cout << "x is smaller than y" << endl; return 0; Example (5) Write a C++ program that takes from the user a number in SR (Saudi Riyal) then the program...

  • This is for c++ Implement the following overloading operator functions: Matrix (int rowSize, int colSize); ~Matrix...

    This is for c++ Implement the following overloading operator functions: Matrix (int rowSize, int colSize); ~Matrix (); Matrix operator + (Matrix & m); Matrix operator += (Matrix & m); Matrix operator += (const int &num); Matrix operator * (Matrix & m); Matrix operator ++(); friend Matrix operator +(const int &num, const Matrix &m); friend istream& operator>> (istream& in, const Matrix& m); friend ostream &operator<<(ostream &os, const Matrix &m); Test your Matrix class withe following main function: cout << "Matrix 1:"...

  • What is the output of the following code snippet? (If there is some kind of syntax...

    What is the output of the following code snippet? (If there is some kind of syntax error indicate this by marking "error" in your answer choice) 1.        int fly = 5; int x;        if (fly-- > 5)               x = 5;        else               x = 2;        if (x++ > 3)               cout << x;        cout << fly << endl; 2.   int i = 0;        bool b = i == 0 || i++ > 0;        if (!b)               cout << i << endl;        else               cout...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT