Errata

Understanding and Using C Pointers

Errata for Understanding and Using C Pointers

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
PDF Page 9
everytime printf("%d", &pi) is.

§7.21.6/9 (C11) says, "If any argument is not the correct type for the corresponding conversion specification, the behavior is undefined."

Use %p format specifer (which requires casting to void* type):

printf("%p", (void *)&pi);

or

printf(""PRTdPTR"", (uintptr_t)&p);

Dominik Mańkowski  May 09, 2016 
Printed Page 11
Section "Pointers to Functions"

Hello, in this section paragraph, either "The function is passed void and returns void" should be "The function is passed an unspecified number of arguments and returns void" or "void (*foo) ()" should be "void (*foo) (void)", is that correct? Below, a simple example to endorse the proposal.

```
void fx1(void (*foo)()) {}
void fx2(void (*foo)(void)) {}

void fn1(void) {}
void fn2(int arg1) {}
void fn3(int arg1, int arg2) {}

int main(void)
{
fx1(fn1); // receives void, as stated
fx1(fn2); // receives int
fx1(fn3); // receives int, int
fx2(fn1); // receives void, as stated
fx2(fn2); // expected ‘void (*)(void)’ but argument is of type ‘void (*)(int)’
fx2(fn3); // expected ‘void (*)(void)’ but argument is of type ‘void (*)(int, int)’
}
```

Thank you in advance!

Daniel Augusto  Feb 14, 2022 
Printed Page 28
below the 'pci' error message

The sentence

"The pointer thinks it is pointing to a constant integer; therefore, it does allow the modification of the integer using the pointer."

should be changed to

"The pointer thinks it is pointing to a constant integer; therefore, it does not allow the modification of the integer using the pointer."

(i.e. the word "not" should be added).

Corsin Pfister  Jan 03, 2017 
Other Digital Version 69
2nd paragraph

after compilation of:

char * pc = ( char * ) malloc ( 6 );
for ( int i = 0 ; i < 8 ; i ++ )
{ * pc [ i ] = 0 ;}

i get the error

[Error] invalid type argument of unary '*' (have 'int').

I think it should be:

char * pc = ( char * ) malloc ( 6 );
for ( int i = 0 ; i < 8 ; i ++ )
{ *(pc+i) = 0 ; }

Many thanks for reply.




Francesco Iannotta  Feb 06, 2018 
Printed Page 77
1st paragraph, 2nd sentence

"we use the fptrOperator type definition" should be changed to "we use the fptrOperation type definition"

Faik Hakan Bilgen  Jun 20, 2019 
Printed Page 77
Bottom

Minor issue with program at bottom of page 77. Needs to change to:
typedef int (*fptrToSingleInt)(int);
typedef int (*fptrToTwoInts)(int,int);

//int add(int, int);
int add(int num1, int num2)
{
return num1 + num2;
}

int main()
{


fptrToTwoInts fptrFirst = add;
fptrToSingleInt fptrSecond = (fptrToSingleInt)fptrFirst;
fptrFirst = (fptrToTwoInts)fptrSecond;
printf("%d\n",fptrFirst(5,6));

return EXIT_SUCCESS;
}
-------------- Run: Debug in StructurePointerToPointer (compiler: GNU GCC Compiler)---------------

Checking for existence: C:\Users\Ed\Programs\C_CodeBlocks\StructurePointerToPointer\bin\Debug\StructurePointerToPointer.exe
Executing: "C:\Program Files (x86)\CodeBlocks/cb_console_runner.exe" "C:\Users\Ed\Programs\C_CodeBlocks\StructurePointerToPointer\bin\Debug\StructurePointerToPointer.exe" (in C:\Users\Ed\Programs\C_CodeBlocks\StructurePointerToPointer\.)
Process terminated with status 0 (0 minute(s), 2 second(s))


Note from the Author or Editor:
It is not clear why the proposed change is necessary. Is a warning or error message generated?

Ed Marsh  Oct 06, 2019 
Printed Page 85
2nd paragraph

The sentence

"The following demonstrates the use of pointers in the implementation of the scalar addition operation."

should be changed to

"The following demonstrates the use of pointers in the implementation of the scalar multiplication operation."

That is, "addition" should be changed to "multiplication".

Corsin Pfister  Jan 04, 2017 
PDF Page 85
2nd paragraph

Because comparison of vector[i], vector+i must be change to *(vector+i).
Specifically you indicate "uses the contents at that address"

tester  Jun 25, 2017 
PDF Page 85
Chapter 4: Differences Between Arrays and Pointers

The code generated by vector[i] is different from the code generated by vector+i.

should be:

The code generated by vector[i] is different from the code generated by *(vector+i)


?

Francesco Iannotta  Feb 22, 2018 
PDF Page 89
code sample

Did not exit from main properly:

||=== Build: Debug in StructurePointerToPointer (compiler: GNU GCC Compiler) ===|
C:\Users\Ed\Programs\C_CodeBlocks\StructurePointerToPointer\main.c||In function 'main':|
C:\Users\Ed\Programs\C_CodeBlocks\StructurePointerToPointer\main.c|670|warning: control reaches end of non-void function [-Wreturn-type]|
||=== Build finished: 0 error(s), 1 warning(s) (0 minute(s), 1 second(s)) ===|
After correction:

#include <string.h>

char* trim(char* phrase) {
char* old = phrase;
char* new = phrase;
while(*old == ' ') {
old++;
}
while(*old) {
*(new++) = *(old++);
}
*new = 0;
return (char*) realloc(phrase,strlen(phrase)+1);
}
int main() {
char* buffer = (char*)malloc(strlen(" cat")+1);
strcpy(buffer," cat");
printf("%s\n",trim(buffer));
return EXIT_SUCCESS;

}


-------------- Build: Debug in StructurePointerToPointer (compiler: GNU GCC Compiler)---------------

mingw32-gcc.exe -Wall -g -c C:\Users\Ed\Programs\C_CodeBlocks\StructurePointerToPointer\main.c -o obj\Debug\main.o
mingw32-g++.exe -o bin\Debug\StructurePointerToPointer.exe obj\Debug\main.o
Output file is bin\Debug\StructurePointerToPointer.exe with size 30.30 KB
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))

Ed Marsh  Oct 06, 2019 
Printed Page 95
1st paragraph

"pmatrix is defined as a pointer to a two-dimensional array of integers, with five elements per column" should be changed to "pmatrix is defined as a pointer to a two-dimensional array of integers, with five elements per row".

Lori Pape  Jun 09, 2022 
PDF, Page 98
middle of the page

printf("%d ", (arr+i)[j]);

should be

printf("%d ", (arr+i*cols)[j]);

to properly access the elements.

Soner Akar  Jul 05, 2017 
PDF Page 122
Last code block

For the line:

printf("%d\n", stringLength(&simpleArray))

The submitted error on <Oct 05, 2013> is incorrect. simpleArray is of type <char []>, and applying the '&' operand produces type <char (*) []>, or pointer to array of char. This is not the same as <char **>.

This will still generate a compiler warning for type incompatibility.

Harrison Xu  May 22, 2018 
PDF Page 136
in the code before last paragraph

it seems "uint" must be "unsigned int"

tester  Jul 07, 2017 
PDF Page 137
the second code

it seems "uint" must be "unsigned int"

tester  Jul 07, 2017 
PDF Page 147
2nd function

This function can cause problems when processing the last node.
For reference, I added the necessary code myself.

void delete(LinkedList *list, Node *node) {
if (node = = list->head) {
if (list->head->next = = NULL) {
list->head = list->tail = NULL;
} else {
 list->head = list->head->next;
}
 } else {
Node *tmp = list->head;
 while (tmp != NULL && tmp->next != node) {
tmp = tmp->next;
}
if (tmp != NULL) {
tmp->next = node->next;
}
// added this.
if (list->tail == node) {
list->tail = tmp;
}
}
free(node);
}

Igor Kang  Nov 12, 2016 
PDF Page 154
Last but one paragraph

I found a mistake in the definition of binary search trees on page 154.
It says: "A common ordering is to add a new node to a tree such that all of the node’s children possess a value less than the parent node and all of the children on the right possess a value greater than the parent node. This is called a binary search tree."
It should say instead that all of the node's left children possess a value less than the parent node and the right children possess a value greater than the parent node.

Mateus Sartorio  Apr 03, 2021