Pointers

Quiz
•
Computers
•
University
•
Medium

Marcela Mera
Used 10+ times
FREE Resource
11 questions
Show all answers
1.
FILL IN THE BLANK QUESTION
2 mins • 1 pt
Given these lines of code, show what would be printed. Let's address in memory of y: 8086, x: 2048
Answer explanation
x holds the value 10.
y is a pointer to x, meaning *y (dereferencing y) gives the value stored at x, which is 10.
2.
FILL IN THE BLANK QUESTION
3 mins • 1 pt
Given the following lines of code, show what would be printed. Assume that the address in memory is x: 080, y: 360, and z: 551.
Answer explanation
This is because x is 100, and both pointers y and z dereference to the value of x.
3.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
What is wrong with the following line of code?
The value 25 should be declared as a pointer type.
The pointer is not initialized correctly; it should point to a valid memory address.
The pointer x should not be declared as int*.
There is no error; the code is valid.
Answer explanation
The code attempts to assign an integer value (25) directly to a pointer (int* x). Pointers should be assigned the address of a variable, not an integer value.
4.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
What is wrong with the following lines of code?
The variable x cannot be assigned to a pointer of a different type.
The const qualifier means x cannot be referenced by a pointer.
The pointer y should be of type const int* instead of double*.
There is no error; the code is valid.
Answer explanation
The line of code attempts to assign a pointer of a different type to a variable that is intended to point to a const int, leading to a type mismatch and potential issues with modifying the pointed-to value.
5.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
What is wrong with the following lines of code?
The variable x cannot be assigned to a pointer.
The pointer y should be of type const int* instead of int*.
The variable x must be mutable to be pointed to by a non-const pointer.
There is no error; the code is valid.
Answer explanation
The code is incorrect because x is declared as const int, meaning its value cannot be modified. A non-const pointer (int* y) suggests that the value can be changed, which contradicts the const qualifier. To maintain const correctness, y should be declared as const int*.
6.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
What is wrong with the following lines of code?
You cannot have two variables with the same name in the same scope.
The pointer y is declared correctly the first time but incorrectly the second time.
The variable x cannot be assigned to a pointer.
There is no error; the code is valid.
Answer explanation
The primary issue in the code is the redeclaration of the variable y with a different type in the same scope, which is not allowed in C++.
7.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
What is wrong with the following lines of code?
The variables x and y cannot be assigned to a pointer.
The pointer z should not be declared as const.
z cannot be reassigned to point to a different address since it is a constant pointer.
There is no error; the code is valid.
Answer explanation
The error in the code arises from attempting to reassign a constant pointer, which is not permitted.
Create a free account and access millions of resources
Similar Resources on Wayground
10 questions
0xDebug - Python

Quiz
•
University
15 questions
Code Combat

Quiz
•
University
10 questions
Programming in C

Quiz
•
University
12 questions
C++ Faili (1)

Quiz
•
University
10 questions
Questionário sobre Javascript

Quiz
•
University
15 questions
Cuestionario sobre Dart

Quiz
•
University
15 questions
BASIC C PROGRAMMING

Quiz
•
University
15 questions
JAVASCRIPT.QUIZ

Quiz
•
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