The book's called Computer Science : A Structured programming approach using C. Written by Forouzan & Richard Gilberg.
A little problem on Chapter 9 about pointers.
I just copy the code below from the text:
char c;
char* pc;
int a;
int* pa;
pc = &c; // Good and valid
pa = &a; // Good and valid
pc = &a; // Error: different types
pa = &a; // Error: different levels
My question is about the last line on the code. It says error coz different levels. I'd like to know what you guys think about the last line, is it really an error? I really confused, if it is not a mistyped error from the book publisher, because I tried the code and the result is that there's no prob with the last line.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The book's called Computer Science : A Structured programming approach using C. Written by Forouzan & Richard Gilberg.
A little problem on Chapter 9 about pointers.
I just copy the code below from the text:
char c;
char* pc;
int a;
int* pa;
pc = &c; // Good and valid
pa = &a; // Good and valid
pc = &a; // Error: different types
pa = &a; // Error: different levels
My question is about the last line on the code. It says error coz different levels. I'd like to know what you guys think about the last line, is it really an error? I really confused, if it is not a mistyped error from the book publisher, because I tried the code and the result is that there's no prob with the last line.
I imagine that it is a typographical error in the book. Few books are perfect. Most publishers make errata available for course texts and you should seek out such information before using the book. You did not state which edition you are using, but errata and updates as well as other course material are avialble for download for the 2nd and 3rd editions here: http://course.cengage.com/search/default.cfm?CFID=9226342&CFTOKEN=84758532&action=SearchResults&chMatch=all&bEntire=0&bIsbn=1&bAllPrd=1&bAllRecs=0&bPubl=1&bTitle=1&bAuthr=1&bFeatr=0&bDocs=0&bITrel=0&series=&criteria=Computer+Science+%3A+A+Structured+programming+approa&submit=SEARCH
I imagine it should read :
pa = a ; // Error: different levels
Personally I thing perhaps the book is labouring a simple point - "types must match or be compatible".
Clifford