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
  • 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...

  • 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...

  • 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...

  • What is the output of the following code? int num = 17;                           //Line 1 double...

    What is the output of the following code? int num = 17;                           //Line 1 double gpa = 3.85;                  //Line 2 bool done;                               //Line 3 done = (num == static_cast<int>( (2 * gpa + 9.3)));    //Line 4 cout << "The value of done is: "<< done << endl;     //Line 5

  • What are the errors in the following code? My professor gave us this prewritten code and...

    What are the errors in the following code? My professor gave us this prewritten code and asked us to find the errors in it so that it can run properly #include <cstdlib> #include <ctime> #include <iostream> using namespace std; // input: integer // output: none // adds five to the given parameter void addFive( int x ) { x += 5; } // input: none // output: a random number int generateRandomNumber() { srand( time(0) ); return rand() % 100;...

  • This is a fill in the code type: // FILL IN THE CODE - Write a...

    This is a fill in the code type: // FILL IN THE CODE - Write a program to multiply 2 numbers, print out the results and print out the original numbers in ascending order. #include <iostream> using namespace std; int main() {   int num1;       // holds 1st number   int num2;       // holds 2nd number   int result;       // holds result of multiplication   int *num1Ptr = nullptr; // int pointer which will be set to point to the 1st number   int *num2Ptr...

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
ADVERTISEMENT