A.6
...
static int x = 1;
int y = x * 2;
void t1() {
y++;
cout << "x: " << x << " | y: " << y << endl;
y += 1;
x -= -1;
}
void t2() {
int* x = &y;
cout << "x: " << x << " | y: " << y << endl;
}
void t3() {
int y = x;
static int x = 2;
cout << "x: " << x + 1 << " | y: " << y + x << endl;
x += y;
}
void t4() {
int y = x + 1;
int& z = y;
z += -1;
cout << "x: " << x + z << " | y: " << y << endl;
}
int main() {
vector<int> vec1{ 1, 3, 5, 7, 9 };
vector<int> vec2{ 2, 4, 6, 8, 10 };
vec1.swap(vec2);
int * ptr = &vec1[1];
y = *(ptr + 2);
t1();
t2();
t3();
t3();
t4();
return 0;
}
This program outputs 5 lines. What are they?
1.
2.
3.
4.
5.
A.7 - 15 Points
int x = 1, y = -1;
void swapplus1(int n1, int n2) {
int temp = n1 + 1;
n1 = n2 - 1;
n2 = temp;
x = x + n1;
}
void swapplus2(int& n1, int& n2) {
int temp = n1 + 1;
n1 = n2 - 1;
n2 = temp;
}
void swapplus3(const int& n1, const int& n2) {
int n1val, n2val, temp = n1 + 1;
n1val = n2 - 1;
n2val = temp;
y -= n2;
}
void swapplus4(int* p1, int* p2) {
int temp = *p1 + 1;
*p1 = *p2 + 1;
*p2 = temp;
x = *p1 + y;
}
void swapplus5(int* &p1, int* &p2) {
int* temp = p1 + 1;
p1 = p2 - 1;
p2 = temp;
}
void print(const int& x, const int& y) {
cout << "\n x: " << x << " |y: " << y;
}
int main() {
int arr[]{ 2, 4, 6, 8, 10, 12, 14 };
y = arr[3] / size(arr) ;
swapplus1(x, y); print(x, y);
swapplus2(x, y); print(x, y);
swapplus3(x, y); print(x, y);
swapplus4(&x, &y); print(x, y);
int *px = &x, *py = &y;
(*px)--;
(*py) -= -7;
swapplus5(px, py); print(x, y);
return 0;
}
This program outputs 5 lines. What are they?
1.
2.
3.
4.
5.
A.7
int x = 1, y = -1;
void swapplus1(int n1, int n2) {
int temp = n1 + 1;
n1 = n2 - 1;
n2 = temp;
x = x + n1;
}
void swapplus2(int& n1, int& n2) {
int temp = n1 + 1;
n1 = n2 - 1;
n2 = temp;
}
void swapplus3(const int& n1, const int& n2) {
int n1val, n2val, temp = n1 + 1;
n1val = n2 - 1;
n2val = temp;
y -= n2;
}
void swapplus4(int* p1, int* p2) {
int temp = *p1 + 1;
*p1 = *p2 + 1;
*p2 = temp;
x = *p1 + y;
}
void swapplus5(int* &p1, int* &p2) {
int* temp = p1 + 1;
p1 = p2 - 1;
p2 = temp;
}
void print(const int& x, const int& y) {
cout << "\n x: " << x << " |y: " << y;
}
int main() {
int arr[]{ 2, 4, 6, 8, 10, 12, 14 };
y = arr[3] / size(arr) ;
swapplus1(x, y); print(x, y);
swapplus2(x, y); print(x, y);
swapplus3(x, y); print(x, y);
swapplus4(&x, &y); print(x, y);
int *px = &x, *py = &y;
(*px)--;
(*py) -= -7;
swapplus5(px, py); print(x, y);
return 0;
}
This program outputs 5 lines. What are they?
1.
2.
3.
4.
5.
A6)
line 1)x: 1 | y: 9
line 2)x: 0x408030 | y: 10
line 3)x: 3 | y: 4
line 4)x: 5 | y: 6
line 5)x: 4 | y: 2
A7) assuming size(arr) return sizeof arr (or is typo for sizeof(arr)) and the function is already declared
output: x: 0 |y: 0
x: -1 |y: 1
x: -1 |y: 0
x: 1 |y: 0
x: 0 |y: 7
if size(arr) return no of elements in arr:
output: x: 1 |y: 1
x: 0 |y: 2
x: 0 |y: 0
x: 2 |y: 1
x: 1 |y: 8
if size() function is not declared then an error will be given
Get Answers For Free
Most questions answered within 1 hours.