I’m working on the following homework problem from C for Scientists and Engineers:
Given the following declarations and assignments, what do these expressions evaluate to?
int a1[10] = {9,8,7,6,5,4,3,2,1}
int *p1, *p2;
p1 = a1+3;
Line 14: p2 = *a1[2];
I’m trying to compile this code with gcc, but when I do so, it gives me the following error:
w03_3_prob15.c: In function 'main':
w03_3_prob15.c:14:7: error: invalid type argument of unary '*' (have 'int')
I’m using the following command to compile:
gcc -o w03_3_prob15 w03_3_prob15.c -std=c99
I’m really not sure what to do. Do you have any ideas on how to fix this error?
The line doesn’t compile because it’s incorrect in the book. From the author’s Errata page: