打印

求助!c语言函数以指针形式调用数组如何实现?

[复制链接]
2021|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
li543117|  楼主 | 2008-8-20 16:07 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

此处定义的数组,在下面供函数调用,编译总是出错,尝试了很多办法还是不行,希望高手能指点一下~~~~~如果要能正常调用该数组,该如何改正或者用其他办法如何实现?小弟不甚感激~~~~


unsigned char Inputdata_1[251574]  

void Display(int addr)   //此处改成过指针的形式,但是后面没改,编译依然无法通过
{
    
    int_t i,j;
    int_t  a,b;
    TempBuffer_img[j] = addr[i*960+j+54];         

}

void mian()
{
Display(Inputdata_1)

}



附:编译错误提示

"main.c", line 53: cc0142:  error: expression must have pointer-to-object type
  TempBuffer_img[j] = addr[i*960+j+54];
                              ^

编译软件对此错误的解释:

Compiler Error: expression must have pointer-to-object type

Description

The expression used does not have a pointer-to-object type. 

Severity

Fatal error

Recovery

The compiler cannot recover from this error.

Example

int a;

int main()
{
return a[1]; /* Error occurs here */
}

How to Fix

Ensure that the expression used has a pointer-to-object type. The lvalue must be for a scalar, and if it is a pointer, it must point to an object.

One of the operands must have a pointer-to-object type, and the other one must be an integral expression. You can make the above example compile by either changing the declaration "int a;" to "int a[];" or by changing the return statement to "return a".



相关帖子

沙发
wxn523| | 2008-8-20 22:27 | 只看该作者

to:求助!c语言函数以指针形式调用数组如何实现?

#include<reg51.h>
#include <intrins.h>
int Inputdata_1[10];
void Display(int *addr)   //此处改成过指针的形式,但是后面没改,编译依然无法通过
{
    
    long  i,j;
    long  TempBuffer_img;
    TempBuffer_img= addr[i*960+j+54];         

}

void main(void)
{
Display(Inputdata_1);
}

使用特权

评论回复
板凳
一朝成名| | 2008-8-21 15:52 | 只看该作者

在仔细看看,数组和指针那章

想要给函数传递一个数组的方法

首先是定义一个指针=数组的首地址

然后对指针进行操作

使用特权

评论回复
地板
HWM| | 2008-8-22 19:29 | 只看该作者

在C/C++中指针和数组(或数组名)具有相似特性

所以在函数中可以用指针变量接受数组名(如type *A),或直观的用不带单元数目的数组类型来说明参数类型(如type A[])。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

32

主题

52

帖子

0

粉丝