伪数组问题,求指教,c和指针第八章第六道题
伪数组,这个代码是什么意思,不理解 ,这个伪数组的偏移量是怎么实现的,求指教程序代码:
#include <stdio.h> #include <stdarg.h> #define reg register int array_offset( int arrayinfo[], ... ); int main() { int a[7] = { 3, 0, 3, 1,4, 2,6}; printf( "array_offset( a, 2, 3, 4 )=%d \n ", array_offset( a, 2, 3, 4 ) ); return 0; } int array_offset( int arrayinfo[], ... ) //可变参数类型 { reg int ndim; reg int offset; reg int lo, hi; reg int i; int s[ 10 ]; va_list subscripts; ndim = *arrayinfo++; printf("ndim:%d\n",ndim); if( ndim >= 1 && ndim <= 10 ) //arrayinfo[0]指定伪数组具有的维数,值必须在1和10之间 { va_start( subscripts, arrayinfo ); //初始化 //printf("subscripts:%c\n",subscripts); for( i = 0; i < ndim; i++ ) { s[i] = va_arg( subscripts, int ); //subscripts指向下一个参数,以及下一个参数的类型 printf("s[%d]=%d\n",i,s[i]); } va_end( subscripts ); offset = 0; for( i = 0; i < ndim; i++ ) { lo = *arrayinfo++; hi = *arrayinfo++; if( s[i] < lo || s[i] > hi ) { return -1; } offset *= hi - lo + 1; offset += s[i] - lo; } return offset; } return -1; }