
puntatori, errori frequenti
Authored by Quentin Meneghini
Computers
University
Used 4+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
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.
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
12 questions
C/C++ C Function
Quiz
•
University
10 questions
C - Pointers
Quiz
•
University
15 questions
AS Computing: Data Structures
Quiz
•
10th Grade - University
16 questions
Classroom Computer Rules
Quiz
•
6th Grade - University
11 questions
Scams and Schemes
Quiz
•
KG - University
15 questions
SSK20193 OPERATING SYSTEM QUIZ 2
Quiz
•
University
15 questions
Coding club Summit Online Quiz
Quiz
•
University
16 questions
OPERATING SYSTEM (All 4 modules)
Quiz
•
University
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
29 questions
Alg. 1 Section 5.1 Coordinate Plane
Quiz
•
9th Grade
22 questions
fractions
Quiz
•
3rd Grade
11 questions
FOREST Effective communication
Lesson
•
KG
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
Discover more resources for Computers
12 questions
IREAD Week 4 - Review
Quiz
•
3rd Grade - University
7 questions
Fragments, Run-ons, and Complete Sentences
Interactive video
•
4th Grade - University
7 questions
Renewable and Nonrenewable Resources
Interactive video
•
4th Grade - University
10 questions
DNA Structure and Replication: Crash Course Biology
Interactive video
•
11th Grade - University
5 questions
Inherited and Acquired Traits of Animals
Interactive video
•
4th Grade - University
5 questions
Examining Theme
Interactive video
•
4th Grade - University
20 questions
Implicit vs. Explicit
Quiz
•
6th Grade - University
7 questions
Comparing Fractions
Interactive video
•
1st Grade - University