4. Using cin, Allocating Memory, and Writing Assignment Statements cin, Memory A
ID: 3888625 • Letter: 4
Question
4.Using cin, Allocating Memory, and Writing Assignment Statements
cin, Memory Allocation, and Assignment Statements
Show the variable name and value of each statement
1.double x;
cin >> x;
//Assume the user enters 3.24.
2.double a, b, c = 0.0;
3.int d = 2, x = 3, y = 4;
4 = d – x + y;
4.double def = 123.5; int y;
y = def;
5.int b = 9.0;
6.int num1= 8, num2 = 3, temp = 0;
temp = num1;
num1 = num2;
num2 = temp;
7.int num;
cin >> num;
//Assume the user enters 8.
num++;
8.int c = 8;
++c;
c--;
9.double x = 5.0;
int y = 4;
x = x + y / 4;
10.double x = 5.0;
int y = 4;
y = x + y/4;
11. int count = 0;
cout << ++count << endl;
cout << count++ << endl;
cout << count << endl;
4.Using cin, Allocating Memory, and Writing Assignment Statements
cin, Memory Allocation, and Assignment Statements
Show the variable name and value of each statement
1.double x;
cin >> x;
//Assume the user enters 3.24.
2.double a, b, c = 0.0;
3.int d = 2, x = 3, y = 4;
4 = d – x + y;
4.double def = 123.5; int y;
y = def;
5.int b = 9.0;
6.int num1= 8, num2 = 3, temp = 0;
temp = num1;
num1 = num2;
num2 = temp;
7.int num;
cin >> num;
//Assume the user enters 8.
num++;
8.int c = 8;
++c;
c--;
9.double x = 5.0;
int y = 4;
x = x + y / 4;
10.double x = 5.0;
int y = 4;
y = x + y/4;
11. int count = 0;
cout << ++count << endl;
cout << count++ << endl;
cout << count << endl;
Explanation / Answer
1.double x; x is uninitialized
cin >> x;
//Assume the user enters 3.24. x = 3.24
2.double a, b, c = 0.0; variables are a,b, and c with value 0
3.int d = 2, x = 3, y = 4; variables d, x, and y
4 = d – x + y; 4 = d - x + y will not change value of variables
d = 2, x = 3, y = 4
4.double def = 123.5; int y; variable of data type double
y = def; def = 123.5
integer y
y = def will give 123 assigned
y since y is an integer.
thus, y = 123
5.int b = 9.0; integer variable b with value 9
6.int num1= 8, num2 = 3, temp = 0;
temp = num1;
num1 = num2;
num2 = temp;
integer variables num1 and num2 will get exchanced
final value of num1 will be 3, num2 = 8 and temp = 8
7.int num;
cin >> num;
//Assume the user enters 8.
num++;
num = 8 as num++ increases value of num by 1
8.int c = 8;
++c;
c--;
c = 8
increase value of c by 1, c = 9
decrease value of c by 1, c = 8
final value of c = 8
9.double x = 5.0;
int y = 4;
x = x + y / 4;
x = 5 + 4/4 = 5 + 1 = 6
final value of x is 6.0 and y will be 4
10.double x = 5.0;
int y = 4;
y = x + y/4;
y = 5 + 4/4 = 5 + 1 = 6
fina value of y is 6 and x will be 5.0
11. int count = 0;
cout << ++count << endl;
increment count and print it = 1, print value 1
cout << count++ << endl;
print count and then increment it = 2, print value 1
cout << count << endl;
print count = 2
1.double x; x is uninitialized
cin >> x;
//Assume the user enters 3.24. x = 3.24
2.double a, b, c = 0.0; variables are a,b, and c with value 0
3.int d = 2, x = 3, y = 4; variables d, x, and y
4 = d – x + y; 4 = d - x + y will not change value of variables
d = 2, x = 3, y = 4
4.double def = 123.5; int y; variable of data type double
y = def; def = 123.5
integer y
y = def will give 123 assigned
y since y is an integer.
thus, y = 123
5.int b = 9.0; integer variable b with value 9
6.int num1= 8, num2 = 3, temp = 0;
temp = num1;
num1 = num2;
num2 = temp;
integer variables num1 and num2 will get exchanced
final value of num1 will be 3, num2 = 8 and temp = 8
7.int num;
cin >> num;
//Assume the user enters 8.
num++;
num = 8 as num++ increases value of num by 1
8.int c = 8;
++c;
c--;
c = 8
increase value of c by 1, c = 9
decrease value of c by 1, c = 8
final value of c = 8
9.double x = 5.0;
int y = 4;
x = x + y / 4;
x = 5 + 4/4 = 5 + 1 = 6
final value of x is 6.0 and y will be 4
10.double x = 5.0;
int y = 4;
y = x + y/4;
y = 5 + 4/4 = 5 + 1 = 6
fina value of y is 6 and x will be 5.0
11. int count = 0;
cout << ++count << endl;
increment count and print it = 1, print value 1
cout << count++ << endl;
print count and then increment it = 2, print value 1
cout << count << endl;
print count = 2
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.