Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Dankco committed Feb 24, 2024
1 parent 5f8723c commit e3ec4c4
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions src/pages/Exercise2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,23 @@ const questions2 = [
],
answer: 'string *ptr = &x;',
answerText: new Map([
['char &ptr = *x;', 'Not quite. Remember that the & operator is used to declare a reference before the equal sign and that the * operator after the equal sign dereferences a variable, meaning that you would try to find the value at memory address 3!'],
['string *ptr = &x;', 'Correct! You can actually declare it as either a char or string pointer.'],
['string *ptr = *x;', 'Not quite. Remember that the * operator after the equal sign dereferences a variable, meaning that you would try to find the value at memory address 3!'],
['char *ptr = &x;', 'Correct! You can actually declare it as either a char or string pointer.']
])
[
'char &ptr = *x;',
'Not quite. Remember that the & operator is used to declare a reference before the equal sign and that the * operator after the equal sign dereferences a variable, meaning that you would try to find the value at memory address 3!',
],
[
'string *ptr = &x;',
'Correct! You can actually declare it as either a char or string pointer.',
],
[
'string *ptr = *x;',
'Not quite. Remember that the * operator after the equal sign dereferences a variable, meaning that you would try to find the value at memory address 3!',
],
[
'char *ptr = &x;',
'Correct! You can actually declare it as either a char or string pointer.',
],
]),
},
];

Expand All @@ -65,11 +77,23 @@ const questions3 = [
],
answer: 'Basketball **basketballPtrPtr = &basketballPtr;',
answerText: new Map([
['Basketball **basketballPtrPtr = basketballPtr;', 'Not quite, this tries to assign a single pointer to a double pointer, which will result in a type error'],
['Basketball **basketballPtrPtr = &basketballPtr;', 'Correct! You want to take the address of the pointer itself and assign that to a double pointer. Note the double * notation here indicating a double pointer.'],
['Basketball *basketballPtrPtr = *basketballPtr;', 'Not quite, this is actually invalid because it tries to assign a basketball to a basketball pointer. Remember that the * operator dereferences the pointer on the right hand side of the equal sign.'],
['Basketball *basketballPtrPtr = basketballPtr;', 'Not quite, this ends up creating another pointer that just points directly to the basketball, since it copies the pointer']
])
[
'Basketball **basketballPtrPtr = basketballPtr;',
'Not quite, this tries to assign a single pointer to a double pointer, which will result in a type error',
],
[
'Basketball **basketballPtrPtr = &basketballPtr;',
'Correct! You want to take the address of the pointer itself and assign that to a double pointer. Note the double * notation here indicating a double pointer.',
],
[
'Basketball *basketballPtrPtr = *basketballPtr;',
'Not quite, this is actually invalid because it tries to assign a basketball to a basketball pointer. Remember that the * operator dereferences the pointer on the right hand side of the equal sign.',
],
[
'Basketball *basketballPtrPtr = basketballPtr;',
'Not quite, this ends up creating another pointer that just points directly to the basketball, since it copies the pointer',
],
]),
},
];

Expand Down

0 comments on commit e3ec4c4

Please sign in to comment.