Looking for Programação test answers and solutions? Browse our comprehensive collection of verified answers for Programação at moodle2425.up.pt.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
Consider (as usual in 64-bit machines) that values of type double are represented using 8 bytes in memory and struct types defined as follows.data1
and data2
struct data1 {
double x;
double y;
};
struct data2 {
data1 a;
data1 b;
data1 c;
};
Assuming that no padding bytes are necessary in the representation of what is the output ofdata1
and data2
cout << sizeof(data1) << ' ' << sizeof(data2);
Consider the following code fragment:
struct data {
double x;
double y;
};
void f(const data& a, data& b) {
... // function body
}
Which of the following instructions is valid (does not cause a compilation error) in the body of function ?f
Consider the following struct types :data1
and data2
struct data1 {
double x;
double y;
};
struct data2 {
data1 a;
data1 b;
data1 c;
};
For a variable which of the following is a valid field access?v
of type data2
What is the output of the following code?
struct data { int x; int y; };
data a { 1, 2 }, b { 3, 4};
a.x += b.y;
b.y *= a.x;
cout << a.x << a.y << b.x << b.y;
Consider the namespace and function definitions below. In which of the following cases would a new function declaration overloading of be invalid?f
namespace a {
int f(int x, int y = 3) { return x + y; }
}
namespace b {
int f(int x=1) { return x + 1; }
double f(int x, double y) { return x + y; }
}
int f(int x) {
return x;
}
What is the output of the following program?
void f(int& x, int& y, int z) {
if (x > y) x = z;
else y = z;
}
int main() {
int a = 1, b = 2, c = 3;
f(a, b, c);
f(a, c, b);
cout << a << ' ' << b << ' ' << c << '\n';
return 0;
}
What is the value returned by f(3)
?
int f(int x, int &c) {
c++;
if (x <= 1) return x;
else return f(x - 1, c) + f(x - 2, c);
}
int f(int n) {
int c = 0;
int r = f(n, c);
return r + c;
}
Consider the following code fragment:
namespace a {
namespace b {
int f(int x, int y=1) { return x + y; }
}
int f(int x) { return x > 1 ? x + 1 : a::b::f(x - 1); }
}
int g(int x) {
return x % 3 == 0 ? a::b::f(x, 3) : a::f(x);
}
What is the value returned by g(x)
for when x
equals 1, 2, and 3 respectively?
What is the output of the following code?
int x = 10;
int& xRef = x;
cout << ++x << " - ";
cout << xRef++ << " - ";
cout << x << " - " << (x==xRef) << endl;
What is the output of the following program?
void f(int& x, int& y) {
if (x > y) {
int t = x;
x = y;
y = t;
}
}
void f(int& x, int y, int& z) {
f(x, y);
f(y, z);
f(x, y);
}
int main() {
int x = 3, y = 1, z = 2;
f(x, y, z);
cout << x << " - " << y << " - " << z << endl;
return 0;
}
Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!