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
12 questions
NCCE Year 4 Repetition in Shapes

Quiz
•
3rd Grade - University
10 questions
C Classes

Quiz
•
University
15 questions
Control Statements - Java

Quiz
•
University
10 questions
C Programming Quiz-5

Quiz
•
University
10 questions
Java Quiz 2

Quiz
•
University
13 questions
Intro to IF statements

Quiz
•
KG - University
14 questions
Java Operators

Quiz
•
University
8 questions
Rekurzió, sorozatok

Quiz
•
University
Popular Resources on Wayground
10 questions
Video Games

Quiz
•
6th - 12th Grade
20 questions
Brand Labels

Quiz
•
5th - 12th Grade
15 questions
Core 4 of Customer Service - Student Edition

Quiz
•
6th - 8th Grade
15 questions
What is Bullying?- Bullying Lesson Series 6-12

Lesson
•
11th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
Discover more resources for Computers
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)

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

Interactive video
•
4th Grade - University
36 questions
Unit 5 Key Terms

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

Interactive video
•
4th Grade - University
15 questions
Properties of Equality

Quiz
•
8th Grade - University
38 questions
WH - Unit 3 Exam Review*

Quiz
•
10th Grade - University
21 questions
Advise vs. Advice

Quiz
•
6th Grade - University
12 questions
Reading a ruler!

Quiz
•
9th Grade - University