logo

Crowdly

Browser

Додати до Chrome

met1501s25-a.sg

Шукаєте відповіді та рішення тестів для met1501s25-a.sg? Перегляньте нашу велику колекцію перевірених відповідей для met1501s25-a.sg в distance3.sg.digipen.edu.

Отримайте миттєвий доступ до точних відповідей та детальних пояснень для питань вашого курсу. Наша платформа, створена спільнотою, допомагає студентам досягати успіху!

Write the exact value printed to standard output stream by the following code fragment:

int foo(int const array[], unsigned long elem_cnt) {

int val = array[0];

for (unsigned long i = 1; i < elem_cnt; ++i) {

val = (array[i] > val) ? array[i] : val;

}

return val;

}

int x[] = {10, -10, 20, -20, 30, -30};

printf("%i", foo(x, sizeof(x)/sizeof(x[0])));

Переглянути це питання

Write the exact value printed to standard output stream by the following code fragment:

int foo(int const array[], unsigned long elem_cnt) {

int val = array[0];

for (unsigned long i = 1; i < elem_cnt; ++i) {

val = (array[i] < val) ? array[i] : val;

}

return val;

}

int x[] = {10, -10, 20, -20, 30, -30};

printf("%i", foo(x, sizeof(x)/sizeof(x[0])));

Переглянути це питання

If the following code fragment cannot be compiled, write [for compile-time error]. If the code fragment generates undefined behavior, write [for undefined behavior]. Otherwise, write the exact text written to the standard output stream.

double grades[] = {-10,20,-30,40,-50};

int sum = 0;

for (unsigned long i = 0; i < sizeof(grades)/sizeof(grades[0]); ++i) {

sum += grades[i];

}

printf("%d", sum);

Brief side-note on undefined behavior: The C standard says that statements such as c = (b = a + 2) - (a = 1); and c = (b = a + 2) - (a = 1); cause undefined behavior [because we don't know whether the left or right operand of operator - is evaluated first]. When a program ventures into the realm of undefined behavior, all bets are off. The program may behave differently when compiled with different compilers. But that's not the only thing that can happen. The program may not compile in the first place, if it compiles it may not run, and if it does run, it may crash, behave erratically, or produce meaningless results. In other words, undefined behavior should be avoided like the plague.

Переглянути це питання

Given the following declaration statement:

double grades[] = {10,20,30,40,50};

write the exact value resulting from the evaluation of expression sizeof(grades) when compiled on a -bit GCC compiler.

Переглянути це питання

If the following code fragment cannot be compiled, write [for compile-time error]. If the code fragment generates undefined behavior, write [for undefined behavior]. Otherwise, write the exact text written to the standard output stream.

#define N (6)

int grades[N] = {5};

for (int i = 1; i < N; ++i) {

grades[i] = i*i+5;

grades[i] = (i > 2) ? 2*(grades[i] - grades[i-1]) : grades[i-1];

}

for (int i = 0; i < N; ++i) {

printf("%d%s", grades[i],(i==N-1?"":","));

}

Brief side-note on undefined behavior: The C standard says that statements such as c = (b = a + 2) - (a = 1); and c = (b = a + 2) - (a = 1); cause undefined behavior [because we don't know whether the left or right operand of operator - is evaluated first]. When a program ventures into the realm of undefined behavior, all bets are off. The program may behave differently when compiled with different compilers. But that's not the only thing that can happen. The program may not compile in the first place, if it compiles it may not run, and if it does run, it may crash, behave erratically, or produce meaningless results. In other words, undefined behavior should be avoided like the plague.

Переглянути це питання

If the following code fragment cannot be compiled, write [for compile-time error]. If the code fragment generates undefined behavior, write [for undefined behavior]. Otherwise, write the exact text written to the standard output stream.

int grades[5];

int i, N;

for (N = sizeof(grades)/sizeof(grades[0]), i = 0; i < N; ++i) {

grades[i] = 2*i+5;

grades[i] -= (i%2 == 0) ? 3 : 0;

}

for (i = 0; i < N; ++i) {

printf("%d%s", grades[i],(i==N-1?"":","));

}

Brief side-note on undefined behavior: The C standard says that statements such as c = (b = a + 2) - (a = 1); and c = (b = a + 2) - (a = 1); cause undefined behavior [because we don't know whether the left or right operand of operator - is evaluated first]. When a program ventures into the realm of undefined behavior, all bets are off. The program may behave differently when compiled with different compilers. But that's not the only thing that can happen. The program may not compile in the first place, if it compiles it may not run, and if it does run, it may crash, behave erratically, or produce meaningless results. In other words, undefined behavior should be avoided like the plague.

Переглянути це питання

If the following code fragment cannot be compiled, write [for compile-time error]. If the code fragment generates undefined behavior, write [for undefined behavior]. Otherwise, write the exact text written to the standard output stream.

int grades[5];

int i, N;

for (N = sizeof(grades)/sizeof(grades[0]), i = 0; i < N; ++i) {

grades[i] = 2*i-3;

}

grades[0] = grades[4],

grades[4] = grades[1],

grades[2] = grades[3]+grades[0];

for (i = 0; i < N; ++i) {

printf("%d%s", grades[i],(i==N-1?"":","));

}

Brief side-note on undefined behavior: The C standard says that statements such as c = (b = a + 2) - (a = 1); and c = (b = a + 2) - (a = 1); cause undefined behavior [because we don't know whether the left or right operand of operator - is evaluated first]. When a program ventures into the realm of undefined behavior, all bets are off. The program may behave differently when compiled with different compilers. But that's not the only thing that can happen. The program may not compile in the first place, if it compiles it may not run, and if it does run, it may crash, behave erratically, or produce meaningless results. In other words, undefined behavior should be avoided like the plague.

Переглянути це питання

If the following code fragment cannot be compiled, write [for compile-time error]. If the code fragment generates undefined behavior, write [for undefined behavior]. Otherwise, write the exact text written to the standard output stream.

#define N (5)

int grades[N] = {10,20,30,40,50};

int i = 0, sum = 0;

while (i++ < N) {

sum += grades[i];

}

printf("%d", sum);

Brief side-note on undefined behavior: The C standard says that statements such as c = (b = a + 2) - (a = 1); and c = (b = a + 2) - (a = 1); cause undefined behavior [because we don't know whether the left or right operand of operator - is evaluated first]. When a program ventures into the realm of undefined behavior, all bets are off. The program may behave differently when compiled with different compilers. But that's not the only thing that can happen. The program may not compile in the first place, if it compiles it may not run, and if it does run, it may crash, behave erratically, or produce meaningless results. In other words, undefined behavior should be avoided like the plague.

Переглянути це питання

If the following code fragment cannot be compiled, write [for compile-time error]. If the code fragment generates undefined behavior, write [for undefined behavior]. Otherwise, write the exact text written to the standard output stream.

#define N (5)

int grades[N] = {10,-20,30,-40,50};

int i = 0, sum = 0;

while (++i < N) {

sum += grades[i];

}

printf("%d", sum);

Brief side-note on undefined behavior: The C standard says that statements such as c = (b = a + 2) - (a = 1); and c = (b = a + 2) - (a = 1); cause undefined behavior [because we don't know whether the left or right operand of operator - is evaluated first]. When a program ventures into the realm of undefined behavior, all bets are off. The program may behave differently when compiled with different compilers. But that's not the only thing that can happen. The program may not compile in the first place, if it compiles it may not run, and if it does run, it may crash, behave erratically, or produce meaningless results. In other words, undefined behavior should be avoided like the plague.

Переглянути це питання

If the following code fragment cannot be compiled, write [for compile-time error]. If the code fragment generates undefined behavior, write [for undefined behavior]. Otherwise, write the exact text written to the standard output stream.

#define N (5)

int grades[N] = {-10, 20, -30, 40, -50};

int i = -1, sum = 0;

while (++i < N) {

sum += grades[i];

}

printf("%d", sum);

Brief side-note on undefined behavior: The C standard says that statements such as c = (b = a + 2) - (a = 1); and c = (b = a + 2) - (a = 1); cause undefined behavior [because we don't know whether the left or right operand of operator - is evaluated first]. When a program ventures into the realm of undefined behavior, all bets are off. The program may behave differently when compiled with different compilers. But that's not the only thing that can happen. The program may not compile in the first place, if it compiles it may not run, and if it does run, it may crash, behave erratically, or produce meaningless results. In other words, undefined behavior should be avoided like the plague.

Переглянути це питання

Хочете миттєвий доступ до всіх перевірених відповідей на distance3.sg.digipen.edu?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!

Browser

Додати до Chrome