logo

Crowdly

Programação

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 data1 and data2

defined as follows.

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 data1 and data2

what is the output of

cout << sizeof(data1) << ' ' << sizeof(data2);
100%
0%
0%
0%
View this question

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

?

0%
0%
0%
100%
View this question

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 v of type data2

which of the following is a valid field access?

0%
0%
0%
100%
View this question

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;

0%
0%
0%
100%
View this question

Consider the namespace and function definitions below. In which of the following cases would a new function declaration overloading of f

be invalid?

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;

}

0%
100%
0%
0%
View this question

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;

}

0%
0%
100%
0%
View this question

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;

}

100%
0%
0%
0%
View this question

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?

100%
0%
0%
0%
0%
View this question

What is the output of the following code?

int x = 10;

int& xRef = x;

cout << ++x << " - ";

cout << xRef++ << " - ";

cout << x << " - " << (x==xRef) << endl;

0%
0%
0%
100%
View this question

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;

}

0%
100%
0%
0%
View this question

Want instant access to all verified answers on moodle2425.up.pt?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!