问题描述
有人能说出如何在不使用
sizeof运算符的情况下测量数组的大小吗?
Can anyone tell how to measure the size of an array without use of
sizeof operator ?
推荐答案
如果在过去几个讨论同样蹩脚问题的几个月内参考其中一个线程,而不是开始
a新线程?
-
int main(void){char p [] =" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\ n",* q =" kl BIcNBFr.NKEzjwCIxNJC" ;; int i = sizeof p / 2; char * strchr(); int putchar(\
); while( * q){i + = strchr(p,* q ++) - p; if(i> =(int)sizeof p)i- = sizeof p-1; putchar(p [i] \
);}返回0;}
How about referring to one of the many threads in the last few
months that discuss this same lame question, instead of starting
a new thread?
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
大小信息在数组声明时给出。当一个
数组传递给一个函数时,sizeof无法评估函数内部数组的大小。
The size information is given at declaration of an array. When an
array is passed into a function, the sizeof can''t evaluate the size of
the array inside the function.
(char *)pover - (char *)p
-
~ / JB \〜
(char*)pover - (char*)p
--
~/JB\~
这篇关于如何测量数组的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!