10. int a = 100, b = 10, c = 34; d; a. compute d = (a / b)* c + ((c *b) – a) / b
ID: 3854980 • Letter: 1
Question
10. int a = 100, b = 10, c = 34; d; a. compute d = (a / b)* c + ((c *b) – a) / b b. compute d = (a % b)* c + ((c *b) – a) / b c. compute d = (a / b)* c - ((c %b) – a) / b 11. int a = 100; char b; float c = 3.5; int d; a. compute d = sizeof(a); b. compute d = sizeof(b); c. compute d = sizeof(c) 12. Sort the following binary operators in order of high to low precedence: +, -, *, /, %, =. 13. What is printed by the following code snippet? int x1 = 2, y1, x2 = 2, y2; y1 = ++x1; y2 = x2++; cout << x1 << " " << x2 << ' '; cout << y1 << " " << y2 << ' '; --x2; y1 = x2++; x1++; y2 = x1--; cout << x1 << " " << x2 << ' '; cout << y1 << " " << y2 << ' '; 14. What is the value of variables a, b, and c in the program below after the statement 1, 2, and 3. Please fill-up the values of a, b, c in the table given below after each statement (1, 2 and 3) is executed. int a = 5; int b = 6; int c; a = (b++) + 3; // Statement 1 c = 2 * a + (++b); // Statement 2 b = 2 * (++c) - (a++);// Statement 3 15. Consider the following section of C++ code: #include “stdafx.h” #include <iostream> using namespace std; int main() { int m = 3, n = 2, x , y;//Variable declarations and initializations x = m + 5; m--; y = (m + 4)/3; n = (n--) + 2; m = m + n/2; m++; x = (--x) * 2 - 3; y = y * 2; n = n + y * 3; cout << "m = " << m << endl; // Statement -1 for output printing cout << "n = " << n << endl; // Statement -2 for output printing cout << "x = " << x << endl; // Statement -3 for output printing cout << "y = " << y << endl; // Statement -4 for output printing return 0; } What will be the value of variables m, n, x and y as printed in the statement -1, statement -2, statement -3 and statement -4? 10. int a = 100, b = 10, c = 34; d; a. compute d = (a / b)* c + ((c *b) – a) / b b. compute d = (a % b)* c + ((c *b) – a) / b c. compute d = (a / b)* c - ((c %b) – a) / b 11. int a = 100; char b; float c = 3.5; int d; a. compute d = sizeof(a); b. compute d = sizeof(b); c. compute d = sizeof(c) 12. Sort the following binary operators in order of high to low precedence: +, -, *, /, %, =. 13. What is printed by the following code snippet? int x1 = 2, y1, x2 = 2, y2; y1 = ++x1; y2 = x2++; cout << x1 << " " << x2 << ' '; cout << y1 << " " << y2 << ' '; --x2; y1 = x2++; x1++; y2 = x1--; cout << x1 << " " << x2 << ' '; cout << y1 << " " << y2 << ' '; 14. What is the value of variables a, b, and c in the program below after the statement 1, 2, and 3. Please fill-up the values of a, b, c in the table given below after each statement (1, 2 and 3) is executed. int a = 5; int b = 6; int c; a = (b++) + 3; // Statement 1 c = 2 * a + (++b); // Statement 2 b = 2 * (++c) - (a++);// Statement 3 15. Consider the following section of C++ code: #include “stdafx.h” #include <iostream> using namespace std; int main() { int m = 3, n = 2, x , y;//Variable declarations and initializations x = m + 5; m--; y = (m + 4)/3; n = (n--) + 2; m = m + n/2; m++; x = (--x) * 2 - 3; y = y * 2; n = n + y * 3; cout << "m = " << m << endl; // Statement -1 for output printing cout << "n = " << n << endl; // Statement -2 for output printing cout << "x = " << x << endl; // Statement -3 for output printing cout << "y = " << y << endl; // Statement -4 for output printing return 0; } What will be the value of variables m, n, x and y as printed in the statement -1, statement -2, statement -3 and statement -4? 10. int a = 100, b = 10, c = 34; d; a. compute d = (a / b)* c + ((c *b) – a) / b b. compute d = (a % b)* c + ((c *b) – a) / b c. compute d = (a / b)* c - ((c %b) – a) / b 11. int a = 100; char b; float c = 3.5; int d; a. compute d = sizeof(a); b. compute d = sizeof(b); c. compute d = sizeof(c) 12. Sort the following binary operators in order of high to low precedence: +, -, *, /, %, =. 13. What is printed by the following code snippet? int x1 = 2, y1, x2 = 2, y2; y1 = ++x1; y2 = x2++; cout << x1 << " " << x2 << ' '; cout << y1 << " " << y2 << ' '; --x2; y1 = x2++; x1++; y2 = x1--; cout << x1 << " " << x2 << ' '; cout << y1 << " " << y2 << ' '; 14. What is the value of variables a, b, and c in the program below after the statement 1, 2, and 3. Please fill-up the values of a, b, c in the table given below after each statement (1, 2 and 3) is executed. int a = 5; int b = 6; int c; a = (b++) + 3; // Statement 1 c = 2 * a + (++b); // Statement 2 b = 2 * (++c) - (a++);// Statement 3 15. Consider the following section of C++ code: #include “stdafx.h” #include <iostream> using namespace std; int main() { int m = 3, n = 2, x , y;//Variable declarations and initializations x = m + 5; m--; y = (m + 4)/3; n = (n--) + 2; m = m + n/2; m++; x = (--x) * 2 - 3; y = y * 2; n = n + y * 3; cout << "m = " << m << endl; // Statement -1 for output printing cout << "n = " << n << endl; // Statement -2 for output printing cout << "x = " << x << endl; // Statement -3 for output printing cout << "y = " << y << endl; // Statement -4 for output printing return 0; } What will be the value of variables m, n, x and y as printed in the statement -1, statement -2, statement -3 and statement -4?Explanation / Answer
10: int a = 100, b = 10, c= 34, d;
a. d = (a/b)*c+((c*b)-a)/b
d = (100/10)*34+((34*10)-100)/10
d = 344
b. d = (a%b)*c+((c*b)-a)/b
d = (100%10)*34+((34*10)-100)/10 // % returns remainder
d = 4
c. d = (a/b)*c+((c%b)-a)/b
d = (100/10)*34+((34%10)-100)/10 // 96/10 = 9 as datatype is int.
d = 349
11. int a = 100; char b; float c = 3.5; int d;
a. d = sizeof(a);
d = 4 bytes // sizeof() function returns the memory occupied by the variable. here 'a' is int so size is 4 byte
b. d = sizeof(b);
d = 4 bytes // sizeof() function returns the memory occupied by the variable. here 'b' is int so size is 4 byte
c. d = sizeof(c);
d = 4 bytes // sizeof() function returns the memory occupied by the variable. here 'c' is int so size is 4 byte
12. binary operators in order of high to low precedence: +, -, *, /, %, =.
Sol: *, /, %, +, -, =.
13. output: 3 3
3 2
3 3
2 4
explanation: in line y1 = ++x1; value of x1 is incremented by one(x1 = 3) and this value is assigned to y1.
in line y2 = x2++; here value of x2 is first read and then incremented. i.e y2 is first assigned to x2 before incrementing, therefore x2 = 3, y2 = 2.
similar thing happens later in the code.
14. output:
a = (b++) + 3; // a = (6++)+3; a = 10
c = 2 * a + (++b); // c = 2*10+(++6); c = 27
b = 2 * (++c) - (a++); // c = 2*(++27) -(10++) // 45
15. output:
m = 5
n = 16
x = 11
y = 4
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.