D大同学   曰:数组作为参数会退化为指针,这个规则应该牢记。。。

KC  曰:当数组首地址被作为指针传递出去之后,应该失去了某种标记结束的记号,使得看起来就是普通的指针
从sizeof和delete [] ptr中可以猜测,编译器应该有某种隐式标记数组大小的方法

#include<stdio.h>
void 
test(int arr[])
{
    
int t;
    
t=sizeof(arr);
    
printf("\n在test函数里array[]大小:%d",t);
}

int main()
{
    
int array[5]={1,2,3,4,5};
    
int e;
    
e=sizeof(array);
    
printf("在主函数里array[]大小:%d",e);
    
test(array);
    
return 0;
}

Tags: ,,. 6,317 views
Home

6 Comments so far

Trackbacks/Pingbacks

Leave a comment

Name(required)
Mail (required),(will not be published)
Website(recommended)

Fields in bold are required. Email addresses are never published or distributed.

Some HTML code is allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
URLs must be fully qualified (eg: http://blog.nlogn.cn),and all tags must be properly closed.

Line breaks and paragraphs are automatically converted.

Please keep comments relevant. Off-topic, offensive or inappropriate comments may be edited or removed.