puntatori, errori frequenti

puntatori, errori frequenti

University

13 Qs

quiz-placeholder

Similar activities

Java Programming I 3

Java Programming I 3

University

17 Qs

ISAC Weekly Quiz 8 (C & DBMS)

ISAC Weekly Quiz 8 (C & DBMS)

University

10 Qs

C++ Assessment

C++ Assessment

University

10 Qs

Debugging-Duel-CodeUp'25

Debugging-Duel-CodeUp'25

University

10 Qs

POINTERS

POINTERS

University

10 Qs

OS Chapter 2 - Operating System Concepts

OS Chapter 2 - Operating System Concepts

University

16 Qs

Quiz on Computer Scince

Quiz on Computer Scince

University

10 Qs

Operating System Chapter 2 Part 2

Operating System Chapter 2 Part 2

University

10 Qs

puntatori, errori frequenti

puntatori, errori frequenti

Assessment

Quiz

Computers

University

Hard

Created by

Quentin Meneghini

Used 4+ times

FREE Resource

13 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

int a;

double *pd;

pd = &a;

compiles

compiles with warning

does not compile

compiles but may result in segmentation fault

Answer explanation

Il codice non compila perché si sta cercando di assegnare l'indirizzo di una variabile intera 'a' a un puntatore di tipo 'double'. Questo è un errore di tipo, poiché i tipi non sono compatibili.

2.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

double b, c, *pd;

b = 3.14;

pd = &c;

*pd = &b;

compiles

compiles with a warning

does not compile

compiles but may result in segmentation fault

Answer explanation

The code does not compile because the line '*pd = &b;' attempts to assign the address of 'b' to the location pointed by 'pd', which is pointing to 'c'. This results in a type mismatch, leading to a compilation error.

3.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

double b, *pd;

*pd = 3.14;

b = *pd;

compiles

compiles with a warning

does not compile

compiles but may result in segmentation fault

Answer explanation

Il codice compila ma può causare un segmentation fault. Questo accade perché il puntatore 'pd' non è inizializzato prima di essere dereferenziato, portando a un accesso a memoria non valida.

4.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

int a;

a = &2;

compiles

compiles with a warning

does not compile

compiles but may result in a segmentation fault

Answer explanation

L'assegnazione 'a = &2;' cerca di assegnare l'indirizzo di un valore letterale, che non è valido. In C, non si può prendere l'indirizzo di un valore costante, quindi il codice non compila.

5.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

double b, c, *pd;

b = 3.14;

c = &(*pd);

compiles

compiles with a warning

does not compile

compiles but may result in segmentation fault

Answer explanation

The code does not compile because 'pd' is a pointer that has not been initialized. Dereferencing an uninitialized pointer leads to undefined behavior, making the statement 'c = &(*pd);' invalid.

6.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

int a;

double b = 3.14, *pd;

pd = &b;

a = *pd;

printf("%d\t%f\n", a, *pd);

compiles

compiles with a warning

does not compile

compiles but may result in segmentation fault

Answer explanation

Il codice compila correttamente. La variabile 'a' riceve il valore di 'b' tramite il puntatore 'pd', che è un cast implicito da double a int. Non ci sono errori di sintassi o di accesso alla memoria.

7.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

double b, *pd;

*pd = 3.14;

&b = pd;

compiles

compiles with a warning

does not compile

compiles but may result in segmentation fault

Answer explanation

Il codice non compila perché si tenta di dereferenziare un puntatore non inizializzato (*pd = 3.14;), il che causa un errore. Inoltre, l'assegnazione &b = pd; è errata poiché pd non è un indirizzo valido.

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?