Using cin, Allocating Memory, and Writing Assignment Statements cin, Memory Allo
ID: 3562003 • Letter: U
Question
Using cin, Allocating Memory, and Writing Assignment Statements cin, Memory Allocation, and Assignment Statements Show the variable name and value of each statement
1. int a, b = 9; a = b;
2. int d = 2, x = 3, y = 1; y + 4 = d - x;
3. short number = 10; number = 0;
4. short number = 0; number = 10; number = number + 5;
5. double value = 12.0; value = 10.0; value = value + .5;
6. const int b = 9;
7. double x = -14.5, y = 22.5; int d = 3; y = d - x + y;
8. double ans = 4;
9. int n; cin >> n; //Assume the user enters 3.24.
10. char a; cin >> a;
Assume the user enters 'b'
11. double x; cin >> x;
//Assume the user enters 3.24.
12. double a, b, c = 0.0;
13. int d = 2, x = 3, y = 4; 4 = d - x + y;
14. double def = 123.5; int y;
y = def;
15. int b = 9.0;
16. int num1= 8, num2 = 3, temp = 0;
temp = num1; num1 = num2; num2 = temp;
17. int num; cin >> num;
//Assume the user enters 8. num++;
18. int c = 8; ++c;
c--;
19. double x = 5.0;
int y = 4;
x = x + y / 4;
20. double x = 5.0;
int y = 4;
y = x + y/4;
21. int count = 0;
cout << ++count << endl;
cout << count++ << endl;
cout << count << endl;
Explanation / Answer
1. int a, b = 9, a = b; values: a = b = 9
2. int d = 2, x = 3, y = 1; y + 4 = d - x; values: d = 2, x = 3, y = 1, but y + 4 = d - x gives compilation error varible value required
3. short number = 10; number = 0; values: number = 0, first statement sets number to 10 but second sets it to 0
4. short number = 0; number = 10; number = number + 5; values : number = 15
5. double value = 12.0; value = 10.0; value = value + .5; values: value = 10.500000
6. const int b = 9; values: b = 9, b can't be modified as const keyword is used
7. double x = -14.5, y = 22.5; int d = 3; y = d - x + y; values: x = -14.5, d = 3, y = 40.000000
8. double ans = 4; values: ans = 4.000000
9. int n; cin >> n; //Assume the user enters 3.24. values: n = 3
10. char a; cin >> a; values: a = 'b'
Assume the user enters 'b'
11. double x; cin >> x; values: x = 3.240000
//Assume the user enters 3.24.
12. double a, b, c = 0.0; values: a, b have garbage values, c = 0.000000
13. int d = 2, x = 3, y = 4; 4 = d - x + y; values: compilation error 4 = d - x + y, variable value required on left side of assignment
14. double def = 123.5; int y; y = def; values: def = 123.500000, y = 123
15. int b = 9.0; values: b = 9
16. int num1= 8, num2 = 3, temp = 0;
temp = num1; num1 = num2; num2 = temp; values: this is swaping of numbers so, num1 = 3, num2 = 8, temp = 8
17. int num; cin >> num;
//Assume the user enters 8. num++; values: num = 9, after inputing 8 value of n is incremented by 1
18. int c = 8; ++c; c--; values: c = 8, as first c is incremented and then decremented leads to original value
19. double x = 5.0;
int y = 4;
x = x + y / 4; values: y = 4, x = 5.0 + 4 / 4 = 6.000000
20. double x = 5.0;
int y = 4;
y = x + y/4; values: x = 5.000000, y = 6
21. int count = 0;
cout << ++count << endl; output: 1, count = 1, count is preincremented
cout << count++ << endl; output: 1, count = 2, count is postincremented
cout << count << endl; output: 2, count = 2
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.