"\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "71e867d9",
"metadata": {},
"source": [
"## Description\n",
"Pointers are variables whose value is an address, which is in another location in memory. Thus it is possible to refer to another variable in memory by that other variables memory address and also manipulate memory.\n"
]
},
{
"cell_type": "markdown",
"id": "4ee3c1f1",
"metadata": {},
"source": [
"## Learning Goals\n"
]
},
{
"cell_type": "markdown",
"id": "58ec20e8",
"metadata": {},
"source": [
"## Self Assessment\n",
"\n",
"Questions that test for the learning goals and allows students to evaluate if they truly understand the topics."
]
},
{
"cell_type": "markdown",
"id": "07524fd7",
"metadata": {},
"source": [
"✅ **<span style=\"color:red\">Question:</span>** What is the correct way to create a pointer so that it points to a string variable named drink in the following code: \n",
" \n",
" string drink = \"Coke\";\n",
"\n",
"1. string* ptr = &drink;\n",
"2. string ptr = drink;\n",
"3. string& ptr = drink*;"
]
},
{
"cell_type": "markdown",
"id": "f1da5683",
"metadata": {},
"source": [
"✅ **<span style=\"color:red\">Question:</span>** For the code below, which of the following is the best way to read the code:\n",
"\n",
" int w = 99;\n",
" int* x = &w;\n",
" int* y = x;\n",
"\n",
"1. Pointer x and Pointer y point to the same address.\n",
"2. Pointer x points to the value \"99 \"and Pointer y points to the the address of w.\n",
"3. Pointer x and Pointer y point to the same value."
]
},
{
"cell_type": "markdown",
"id": "7e232e3c",
"metadata": {},
"source": [
"✅ **<span style=\"color:red\">Question:</span>** For the code below, which of the following is true:\n",
"\n",
" int w = 99;\n",
" int* x = &w;\n",
" int* y = x;\n",
"\n",
"1. x and y have the same name.\n",
"2. x and y have the same address.\n",
"3. x and y have the same value."
]
},
{
"cell_type": "markdown",
"id": "0843ee02",
"metadata": {},
"source": [
"## TODO: DIRK will work on a list of list with pointers"
]
},
{
"cell_type": "markdown",
"id": "6527d414",
"metadata": {},
"source": [
"## TODO: Reword the second question"
]
},
{
"cell_type": "markdown",
"id": "81760d5f",
"metadata": {},
"source": [
"✅ **<span style=\"color:red\">Optional Question:</span>** Example Question:\n",
"\n",
" \n",
"\n",
"1. AN2 1.\n",
"2. ANS 2.\n",
"3. ANS 3."
]
},
{
"cell_type": "markdown",
"id": "5d237ca9",
"metadata": {},
"source": [
"## Training Materials\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "21f9b14e",
"metadata": {},
"source": [
"Introduction to Pointers in C++ in 6 minutes (https://youtu.be/fBlM7pR2r_Q)"
]
},
{
"cell_type": "markdown",
"id": "68f2cbdb",
"metadata": {},
"source": [
"Pointer Material with exercises (https://www.w3schools.com/cpp/cpp_pointers.asp)"
]
},
{
"cell_type": "markdown",
"id": "dd1da075",
"metadata": {},
"source": [
"Pointer Material (https://www.programiz.com/cpp-programming/pointers)"
"Written by <<YOUR NAME HERE>>, Michigan State University \n",
"As part of the Data Science Bridge Project \n",
" \n",
"<a rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc/4.0/\"><img alt=\"Creative Commons License\" style=\"border-width:0\" src=\"https://i.creativecommons.org/l/by-nc/4.0/88x31.png\" /></a><br />This work is licensed under a <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc/4.0/\">Creative Commons Attribution-NonCommercial 4.0 International License</a>."
('answercheck.py', <http.client.HTTPMessage at 0x7f646df0f820>)
%% Cell type:markdown id:3c2a4f39 tags:
# Pointers
Understanding Pointers and their purpose
%% Cell type:markdown id:2b78245b tags:
Pointer Dog:

%% Cell type:markdown id:71e867d9 tags:
## Description
Pointers are variables whose value is an address, which is in another location in memory. Thus it is possible to refer to another variable in memory by that other variables memory address and also manipulate memory.
%% Cell type:markdown id:4ee3c1f1 tags:
## Learning Goals
%% Cell type:markdown id:58ec20e8 tags:
## Self Assessment
Questions that test for the learning goals and allows students to evaluate if they truly understand the topics.
%% Cell type:markdown id:07524fd7 tags:
✅**<span style="color:red">Question:</span>** What is the correct way to create a pointer so that it points to a string variable named drink in the following code:
string drink = "Coke";
1. string* ptr = &drink;
2. string ptr = drink;
3. string& ptr = drink*;
%% Cell type:markdown id:f1da5683 tags:
✅**<span style="color:red">Question:</span>** For the code below, which of the following is the best way to read the code:
int w = 99;
int* x = &w;
int* y = x;
1. Pointer x and Pointer y point to the same address.
2. Pointer x points to the value "99 "and Pointer y points to the the address of w.
3. Pointer x and Pointer y point to the same value.
%% Cell type:markdown id:7e232e3c tags:
✅**<span style="color:red">Question:</span>** For the code below, which of the following is true:
int w = 99;
int* x = &w;
int* y = x;
1. x and y have the same name.
2. x and y have the same address.
3. x and y have the same value.
%% Cell type:markdown id:0843ee02 tags:
## TODO: DIRK will work on a list of list with pointers
%% Cell type:markdown id:6527d414 tags:
## TODO: Reword the second question
%% Cell type:markdown id:81760d5f tags:
✅**<span style="color:red">Optional Question:</span>** Example Question:
1. AN2 1.
2. ANS 2.
3. ANS 3.
%% Cell type:markdown id:5d237ca9 tags:
## Training Materials
%% Cell type:markdown id:21f9b14e tags:
Introduction to Pointers in C++ in 6 minutes (https://youtu.be/fBlM7pR2r_Q)
%% Cell type:markdown id:68f2cbdb tags:
Pointer Material with exercises (https://www.w3schools.com/cpp/cpp_pointers.asp)
%% Cell type:markdown id:dd1da075 tags:
Pointer Material (https://www.programiz.com/cpp-programming/pointers)
<IPython.lib.display.YouTubeVideo at 0x7f646ce74370>
%% Cell type:markdown id:44b461a0 tags:
---
Written by <<YOURNAMEHERE>>, Michigan State University
As part of the Data Science Bridge Project
<arel="license"href="http://creativecommons.org/licenses/by-nc/4.0/"><imgalt="Creative Commons License"style="border-width:0"src="https://i.creativecommons.org/l/by-nc/4.0/88x31.png"/></a><br/>This work is licensed under a <arel="license"href="http://creativecommons.org/licenses/by-nc/4.0/">Creative Commons Attribution-NonCommercial 4.0 International License</a>.