Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

6. What will be the value of the variable d in the statement given below if x, y

ID: 3855394 • Letter: 6

Question

6.      What will be the value of the variable d in the statement given below if x, y, and z are int variables, and x = 10, y = 15, and z = 20. You can give the results in 1 and 0 or true and false (true means 1 and false means 0).

d = (x <= z % y - 2) && (y >= z)

7.      int a = 100, b = 11, c;

a.       compute c = a<<2

b.      compute c = b<<2

8.      Suppose that x = (2B6E)16 , y = (5AE9)16 and Z = (27BC)16 and Solve the expression = (x|~y&~z) and return the result in hexadecimal.       

9.      int a = 110, b = 10, c;

a.       compute c = (a==100) ? b : a

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

(6). 0

code :

#include <iostream>
using namespace std;

int main() {
int x = 10, y = 15, z = 20;
double d = (x <= z % y - 2) && (y >= z) ;
cout << d << endl ;
return 0;
}

output :

because the condition is false. 0 && 0 = false

###########################################

(7)

int a = 100, b = 11, c;

a.       compute c = a<<2 = 400

b.      compute c = b<<2 = 44

Code :

#include <iostream>
using namespace std;

int main() {
int a = 100, b = 11, c;
int c1 = a<<2;
int c2 = b<<2;

cout << c1 << endl ;
cout << c2 << endl ;
return 0;
}

output :

Because if you shift a value by 2 the result is that value multiplies by 4. So 100* 4 = 400 and 11*4 = 44

##############################################

(8)

code :

#include <iostream>
using namespace std;

int main() {
int x = 0x2B6E , y = 0x5AE9 ,z = 0x27BC ;
int c1 = x|~y&~z ;

std::cout << std::hex << c1 << ' ';

return 0;
}

output :

oxAB6E

############################################################

(9)

Code :

#include <iostream>
using namespace std;

int main() {
int a = 110, b = 10, c;
c = (a==100) ? b : a;

cout << c << endl;

return 0;
}

Output :

Because the a is not 100. So the value a is assigned to the c

#####################################################

(10 ).

(a) d = (a/b)*c + ((c*b)–a)/b;
   d= (100/10)*34 + ((34*10)-100)/10
   d = 10*34 + (340 - 100)/10
   d= 340 + 240/10
   d= 340 + 24 = 364
(b) d = (a % b)* c + ((c *b) – a) / b;
   d= (100 % 10)*34 + ((34*10)-100)/10
   d = 0*34 + (340 - 100)/10
   d= 0 + 240/10
   d= 0 + 24 = 24  
(C) d = (a / b)* c - ((c %b) – a) / b;  
   d= (100 / 10)*34 - ((34 % 10)-100)/10
   d = 10*34 - (4 - 100)/10
   d= 340 + 96/10
   d= 340 + 9 = 349

###################################################

(11)

code :

#include <iostream>
using namespace std;

int main() {
int a = 100; char b; float c = 3.5; int d;
int d1 = sizeof(a);
int d2 = sizeof(b);
int d3 = sizeof(c);

cout << d1 << endl;
cout << d2 << endl;
cout << d3 << endl;

return 0;
}

output :

int d1 = sizeof(a) = 4
int d2 = sizeof(b); =1
int d3 = sizeof(c); = 4

Because the integer value stored in 4 bytes and charcter stores in 1 byte

#############################################

(12)

Sortof the binary operators in order of high to low precedence: *, /, %, +, -, =.