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!

What is the output of the following code fragment?

int a[] { 2, 1, 0 };

int n = 0;

for (int v : a) { v++; n += v; }

for (int& v : a) { n++; v += n; }

std::cout << n << ' '

<< a[0] << ' ' << a[1] << ' ' << a[2] << '\n';

0%
0%
100%
0%
View this question

Consider (as usual in 64-bit machines) that values of type int, and char

are represented using 4 and 1 bytes in memory, respectively. What is the output of the following program (assuming no padding is necessary for the struct

types involved)?

struct event {

char id[4];

int code;

};

struct week {

int number;

event events[7];

};

int main() {

week w;

std::cout << sizeof(w) << '\n';

return 0;

}

100%
0%
0%
0%
View this question

What is the output of the following code fragment?

char s[] = "2LEIC 022";

int i = 0;

do { i++; } while (s[i] != '\0' && s[i] != '2');

s[i] = '\0';

std::cout << i << " \"" << s << "\"\n";

0%
0%
0%
100%
View this question

For what value of i

, read from the input in the following code fragment, there is a buffer overflow?

struct data { int x; int y; };

data a[] { {1, 2}, {3, 3}, {2, 1}, {0, 0} };

int i;

std::cin >> i;

std::cout << a[a[a[i].x].y - 1].x;

100%
0%
0%
0%
View this question

For what value of i

, read from the input in the following code fragment, is there a buffer overflow?

int a[] = { 1, 3, 2, 0 };

int i;

cin >> i;

a[a[i] + 1] = a[i];

100%
0%
0%
0%
View this question

Consider a C++ function of the form:

int f(const int a[], int b[]) {

int c[] { 0, 1, 2 };

// ...

return c[0] + c[1] + c[2];

}

Which of the following possibilities to complete the code of f is valid (does not cause a compilation error) after the declaration of c and before the return

instruction?

100%
0%
0%
0%
View this question

Consider (as usual in 64-bit machines) that values of type long, int, and char

are represented using 8, 4, and 1 bytes in memory, respectively.

How many bytes are required for the representation of v

shown in the code fragment below (assuming no padding)?

struct data {

long a;

int b[3];

char c[12];

};

data v[4];

100%
0%
0%
0%
View this question

What is the output of the following code fragment?

struct data {

int i;

int j;

int v;

};

data d[3] { {0, 1, 2}, {3, 2, 1}, {0, 1, 2} };

std::cout << d[2].j << ' ' << d[d[0].v].i << ' ' << d[d[1].j].v << '\n';

0%
0%
100%
0%
View this question

What is the output of the following code fragment?

char s[] = "C/C++ is fun!";

int i = 0;

while (s[i] != '\0' && s[i] != ' ') i++;

s[i] = '\0';

std::cout << i << ' ' << s << '\n';

0%
100%
0%
0%
View this question

Assume that there is a struct type called data and that we wish to program a function f that takes 2 data input (read-only) parameters a and b and yields a result also of type data

.

What is the most appropriate declaration of f, if sizeof(data)

exceeds the word size of 8 bytes in a 64-bit machine?

100%
0%
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!