数组做为参数时从汇编语言看传递的是指向该数组的指针还是数组本身?

Keanu_Rocky 2002-10-15 04:13:10
只要有说服力,一定给高分。
...全文
69 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
johnmack 2002-10-15
  • 打赏
  • 举报
回复
是指针啦!
Keanu_Rocky 2002-10-15
  • 打赏
  • 举报
回复
谢啦,我明白啦。
同桌老王 2002-10-15
  • 打赏
  • 举报
回复
废话,是指针
gongdath 2002-10-15
  • 打赏
  • 举报
回复
应该是指针.
筷子哥 2002-10-15
  • 打赏
  • 举报
回复
指针!
你可以想象一下编译过程,
词法分析的时候,应该是指针吧,产生参数表
那么,中间代码的时候,有必要具体到内存单元吗,不利于兼容吧
所以,还是指针
功名半纸 2002-10-15
  • 打赏
  • 举报
回复
指针!
前面几位都说的很清楚了!
bonnyone 2002-10-15
  • 打赏
  • 举报
回复
不管用指针还是数组,他们传递的统统是数组或指针的头地址。
举个例子:
#include <iostream.h>
#include <time.h>
#include <stdlib.h>

void swap(int &a,int &b)
{
int temp;
temp=a;
a=b;
b=temp;
}

void shell(int *a,int n) //可以改成void shell(int a[10],int n)
//其中10可以改成其他数,效果一样
{
for(int gap=n/2;gap>0;gap/=2)
for(int j=gap;j<n;j++)
for(int i=j-gap;i>0&&a[i]<a[i+gap];i-=gap)
swap(a[i],a[i+gap]);
}

void main()
{
time_t t;
int arr[20];
srand((unsigned int)time(&t));
for(int i=0;i<20;i++)
{
arr[i]=rand()%1000;
cout<<arr[i]<<" ";
if((i+1)%11==0)
cout<<endl;
}
shell(arr,20);
for(i=0;i<20;i++)
{
cout<<arr[i]<<" ";
if(i%10==0)
cout<<endl;
}
cout<<endl;
}
zhf0021 2002-10-15
  • 打赏
  • 举报
回复
是指针,上面几为讲的很清楚
asvaboy1980 2002-10-15
  • 打赏
  • 举报
回复
指针:)
blh 2002-10-15
  • 打赏
  • 举报
回复
不管你的函数定义成
fun(char *p)
还是
fun(char p[])
编译器按照相同的方法处理,呵呵,看看下面的c源码和汇编代码

char c[10];

void fun(char p[])
{
p[0] = 10;
}

void fun1(char *p)
{
p[0] = 10;
}

char a;
int main()
{
fun1(&a);
fun(c);
fun1(c);
return 0;
}

~
.file "exa35.c"
.version "01.01"
gcc2_compiled.:
.text
.align 4
.globl fun
.type fun,@function
fun:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
movb $10, (%eax)
popl %ebp
ret
.Lfe1:
.size fun,.Lfe1-fun
.align 4
.globl fun1
.type fun1,@function
fun1:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
movb $10, (%eax)
popl %ebp
ret
.Lfe2:
.size fun1,.Lfe2-fun1
.align 4
.globl main
.type main,@function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
subl $12, %esp
pushl $a
call fun1
addl $16, %esp
subl $12, %esp
pushl $c
call fun
addl $16, %esp
subl $12, %esp
pushl $c
call fun1
addl $16, %esp
movl $0, %eax
leave
ret
.Lfe3:
.size main,.Lfe3-main
.comm c,10,1
.comm a,1,1
.ident "GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.3 2.96-110)"
step_by_step 2002-10-15
  • 打赏
  • 举报
回复
这个问题还有疑义么?当然是指针了。
你函数申明的时候void fn(char *pchArray);和void fn(char pchArray[]);
效果一样
blue_coco 2002-10-15
  • 打赏
  • 举报
回复
应该是指针。
有个例子:

a:
char a[100];
sizeof(a) = 100; ///////////////////////1

b:
void fun(char a[100])
{
sizeof(a) = 4;//////////////////////2
}

由1,2两处的值可以发现。

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧