一元“*"的无效类型参数(有“int") [英] invalid type argument of unary '*' (have 'int')

查看:127
本文介绍了一元“*"的无效类型参数(有“int")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理来自 C 的以下作业问题对于科学家和工程师:

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];

我正在尝试用 gcc 编译这段代码,但是当我这样做时,它给了我以下错误:

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:

Page 438, line 17 from the bottom.
p2 = *a1[2]; 
should be  p2 = &a1[2];

这篇关于一元“*"的无效类型参数(有“int")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆