puntatori, errori frequenti

Quiz
•
Computers
•
University
•
Hard
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
Similar Resources on Wayground
15 questions
Coding club Summit Online Quiz

Quiz
•
University
10 questions
C - Pointers

Quiz
•
University
16 questions
Java Flashcards

Quiz
•
University
10 questions
Data Mining - B

Quiz
•
University
10 questions
NumPy

Quiz
•
9th Grade - University
16 questions
OPERATING SYSTEM (All 4 modules)

Quiz
•
University
15 questions
SSK20193 OPERATING SYSTEM QUIZ 2

Quiz
•
University
15 questions
AS Computing: Data Structures

Quiz
•
10th Grade - University
Popular Resources on Wayground
10 questions
Video Games

Quiz
•
6th - 12th Grade
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
10 questions
UPDATED FOREST Kindness 9-22

Lesson
•
9th - 12th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
20 questions
US Constitution Quiz

Quiz
•
11th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
Discover more resources for Computers
10 questions
Would you rather...

Quiz
•
KG - University
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)

Quiz
•
8th Grade - University
7 questions
Force and Motion

Interactive video
•
4th Grade - University
10 questions
The Constitution, the Articles, and Federalism Crash Course US History

Interactive video
•
11th Grade - University
7 questions
Figurative Language: Idioms, Similes, and Metaphors

Interactive video
•
4th Grade - University
20 questions
Levels of Measurements

Quiz
•
11th Grade - University
16 questions
Water Modeling Activity

Lesson
•
11th Grade - University
10 questions
ACT English prep

Quiz
•
9th Grade - University